socket timeout being ignored



Say I have the following script:

<?
$timeout = 5;
$start = time();
$fsock = fsockopen('125.1.119.10',80,$errno,$errstr,$timeout);

// reduce $timeout by the amount of time that it took for fsockopen to
connect.
$timeout-=(time()-$start);

socket_set_timeout($fsock,$timeout);

fputs($fsock,"GET http://www.google.com/ HTTP/1.0\r\n");
fputs($fsock,"Host: www.google.com\r\n\r\n");

while ( !feof($fsock) )
{
echo fgets($fsock);
}

fclose($fsock);
?>

As you can tell, the timeout is set to 5 seconds in fsockopen and then
is set to how ever many seconds out of that 5 that fsockopen didn't
take to connect.

All in all, the whole script should run in, at most, 5 seconds. Or
atleast it seems like it should. Sometimes, however, it doesn't - it
takes several minutes. And unfortunately, this happens enough times to
be kinda a nuisance. And I have no idea what the problem is.

Any ideas?

.



Relevant Pages

  • Re: scp failing
    ... When you run scp from the command line, ... taking out the timeout block does *not* remove ... script and the suggested fixes, ... this script is running another script on a remote computer. ...
    (comp.lang.tcl)
  • Re: Script Time Out Issue
    ... I am suspicious of the ODBC - I checked on the ODBC timeout and it relates ... then produces an error message that it failed to perform one of the LMS API ... seconds recovered and the script ran to completion. ...
    (microsoft.public.windows.server.scripting)
  • Re: bourne shell user interaction
    ... I have a script which loops but I'd like it to see if the user wants to ... I think read and expect can't timeout so I couldn't see how they could ... If the exit code is 0, the user pressed a key within the timeout period. ...
    (comp.unix.shell)
  • Re: scp failing
    ... When you run scp from the command line, ... taking out the timeout block does *not* remove ... script and the suggested fixes, ... this script is running another script on a remote computer. ...
    (comp.lang.tcl)
  • Re: scp failing
    ... When you run scp from the command line, ... taking out the timeout block does *not* remove ... script and the suggested fixes, ... this script is running another script on a remote computer. ...
    (comp.lang.tcl)