note 20114 added to function.fsockopen
| From: | jroberts at php2 dot chek dot com | Date: | Fri, 22 Mar 2002 17:40:54 +0000 |
| Subject: | note 20114 added to function.fsockopen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-28084@lists.php.net to get a copy of this message | ||
Has anyone seen the timeout parameter on fsockopen() actually WORK?
I'm running PHP 4.0.6 on a linux system. I'm using fsockopen(), fputs() and fread() to
retrieve the headers of a remote file. The key elements of the test script are:
$fp = fsockopen("www.krasnapolsky.sr", 80, &$errno, &$errstr, 0.2);
fputs($fp, "HEAD /default.htm HTTP/1.0\nHost:www.krasnapolsky.sr\n\n");
$response=fread($fp, 1024);
// (note that I'm deliberately using www.krasnapolsky.sr because I know it's very slow
from my location in the U.S.)
By using a timer based on microtime(); I see that the actual fsockopen() step is taking up to 3.5
seconds without failing. As far as I can tell, I'm telling PHP to fail if the connect takes
more than 0.2 seconds. The function signature does specify that the timeout parameter is of type
float (and I've tried 1 with no better luck).
The script works fine (retrieves the headers), but I can't tolerate the possibility that it
might hang for many seconds -- I'd rather the script give up after a second or so.
BTW, I've found that calling socket_set_timeout($fp, 0, 250); after fsockopen DOES let me limit
the fputs(); and fread(); to 0.25 seconds. But... that's not useful in limiting the actual
socket connect call.
Thanks for any insights or help.
--
http://www.php.net/manual/en/function.fsockopen.php
http://master.php.net/manage/user-notes.php?action=edit+20114
http://master.php.net/manage/user-notes.php?action=delete+20114
http://master.php.net/manage/user-notes.php?action=reject+20114