View Single Post
Old 12-16-2003, 10:31 PM   #3 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
well, now you're getting into deep networking land, and probably a bit out of the scope of php's file implementation.

you would probably want to use non-blocking sockets and implement the http transaction yourself. seems that php's socket functions are pretty young at the moment, so it might be safer to write an external program that will accomplish this for you. if you want to stick to php, here's an example someone posted on the php.net socket_connect() comment section (although the right way to do this would have been to use select() instead of continuous connecting).

PHP Code:
<?
   $host 
"127.0.0.1";
   
$port "80";
   
$timeout 15;  //timeout in seconds

   
$socket socket_create(AF_INETSOCK_STREAMSOL_TCP)
     or die(
"Unable to create socket\n");

   
socket_set_nonblock($socket)
     or die(
"Unable to set nonblock on socket\n");

   
$time time();
   while (!@
socket_connect($socket$host$port))
   {
     
$err socket_last_error($socket);
     if (
$err == 115 || $err == 114)
     {
       if ((
time() - $time) >= $timeout)
       {
         
socket_close($socket);
         die(
"Connection timed out.\n");
       }
       
sleep(1);
       continue;
     }
     die(
socket_strerror($err) . "\n");
   }

   
socket_set_block($this->socket)
     or die(
"Unable to set block on socket\n");
?>
joe_bruin is offline   Reply With Quote