#36216 [Opn->Fbk]: timeout doesnt works in fsockopen
| From: | tony2001@php.net | Date: | Tue, 31 Jan 2006 06:50:41 +0000 |
| Subject: | #36216 [Opn->Fbk]: timeout doesnt works in fsockopen | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-92678@lists.php.net to get a copy of this message | ||
ID: 36216
Updated by: tony2001@php.net
Reported By: ipmax at freesurf dot fr
-Status: Open
+Status: Feedback
Bug Type: Sockets related
Operating System: debian
PHP Version: 5.1.2
New Comment:
Please try using this CVS snapshot:
http://snaps.php.net/php5.1-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php5.1-win32-latest.zip
Previous Comments:
------------------------------------------------------------------------
[2006-01-31 04:52:12] ipmax at freesurf dot fr
You can delete previous post, here is a good example :
This echo "connected," and hangs for ever, timout doesnt works :
---------------------------------
$scfp=fsockopen("generation.elliptic.fr", 8060,&$errno,&$errstr,5);
if(!$scfp) {echo "error"; exit;
} else {
echo "connected,";
fputs($scfp,"GET /admin.cgi\r\n\r\n");
while(!feof($scfp)) {$page .= fgets($scfp); }
fclose($scfp);
//////////////////////
This works, considering timout is checked in the fgets loop.
stream_set_timeout() replace the bug of fsockopen that doesnt timeout.
$scfp=fsockopen("generation.elliptic.fr", 8060,&$errno,&$errstr,2);
if(!$scfp) {echo "error"; exit;
} else {
echo "connected,";
stream_set_timeout($scfp,2);
fputs($scfp,"GET /admin.cgi\r\n\r\n");
while(!feof($scfp)) {$page .= fgets($scfp);
$info = stream_get_meta_data($scfp);
if ($info['timed_out']) { echo "timeout"; exit; }
}
fclose($scfp);
---------------------
PHP 5.1.1-1.dotdeb.2 (cli) (built: Dec 1 2005 12:46:40)
------------------------------------------------------------------------
[2006-01-31 04:50:58] ipmax at freesurf dot fr
Please use this adress to test :
$scfp=fsockopen("generation.elliptic.fr", 8060,&$errno,&$errstr,1);
I dont know what firewall there is, but sometimes, my demo is correct,
on microsoft it is not.
------------------------------------------------------------------------
[2006-01-31 04:45:19] ipmax at freesurf dot fr
did a mistake in the first post, here is the way to understand. Timeout
works only if add stream_set_timeout() to the inloop stream. Why the
fsokopen timeout doesnt timeout ? no idea.
--------------------------------
This echo "connected," and hangs for ever, timout doesnt works :
---------------------------------
$scfp=fsockopen("www.microsoft.com", 111,&$errno,&$errstr,5);
if(!$scfp) {echo "error"; exit;
} else {
echo "connected,";
fputs($scfp,"GET /admin.cgi\r\n\r\n");
while(!feof($scfp)) {$page .= fgets($scfp); }
fclose($scfp);
//////////////////////
This works, considering timout is checked in the fgets loop.
stream_set_timeout() replace the bug of fsockopen that doesnt timeout.
$scfp=fsockopen("www.microsoft.com", 111,&$errno,&$errstr,2);
if(!$scfp) {echo "error"; exit;
} else {
echo "connected,";
stream_set_timeout($scfp,2);
fputs($scfp,"GET /admin.cgi\r\n\r\n");
while(!feof($scfp)) {$page .= fgets($scfp);
$info = stream_get_meta_data($scfp);
if ($info['timed_out']) { echo "timeout"; exit; }
}
fclose($scfp);
---------------------
PHP 5.1.1-1.dotdeb.2 (cli) (built: Dec 1 2005 12:46:40)
------------------------------------------------------------------------
[2006-01-31 04:40:13] ipmax at freesurf dot fr
we are talking here of a fsockopen connection attempt to a non
responding remote server, like a server with DROP iptable firewall.
Noteven responding error or 404, just not responding at all.
fsockopen never timeout, fgets never find the EOF.
=> Hang.
------------------------------------------------------------------------
[2006-01-31 04:33:20] ipmax at freesurf dot fr
This echo "connected," and hangs for ever, timout doesnt works :
---------------------------------
$scfp=fsockopen("www.microsoft.com", 111,&$errno,&$errstr,5);
if(!$scfp) {echo "error"; exit;
} else {
echo "connected,";
stream_set_timeout($scfp,2);
fputs($scfp,"GET /admin.cgi\r\n\r\n");
while(!feof($scfp)) {$page .= fgets($scfp); }
fclose($scfp);
//////////////////////
This works, considering timout is checked in the fgets loop.
stream_set_timeout() replace the bug of fsockopen that doesnt timeout.
$scfp=fsockopen("www.microsoft.com", 111,&$errno,&$errstr,2);
if(!$scfp) {echo "error"; exit;
} else {
echo "connected,";
stream_set_timeout($scfp,2);
fputs($scfp,"GET /admin.cgi\r\n\r\n");
while(!feof($scfp)) {$page .= fgets($scfp);
$info = stream_get_meta_data($scfp);
if ($info['timed_out']) { echo "timeout"; exit; }
}
fclose($scfp);
---------------------
PHP 5.1.1-1.dotdeb.2 (cli) (built: Dec 1 2005 12:46:40)
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/36216
--
Edit this bug report at http://bugs.php.net/?id=36216&edit=1