|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-01-30 20:29 UTC] ipmax at freesurf dot fr
Description: ------------ fsockopen hang if remote server doesnt reply, like no dns, or server down, or firewall drop paquets. Timeout only works if remote server reply something if a firewall drop paquets, then timeout wont work, and fsockopen hang forever. Same problem on socket_server This is a big problem, that is why many people see theyr script hanging when using fsockopen. I v seen this bug on redhat php 4, and debian php 5 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 07 12:00:02 2025 UTC |
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)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)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.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)Try this one, it reply connected, but hangs for ever. Tested on Debian and redhat. Same Result. $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);Host generation.elliptic.fr is alive and fsockopen() succeeds for me. But with that's what I get with sf.net, for example: # time ./sapi/cli/php -r 'var_dump(fsockopen("sf.net", 8060,&$errno,&$errstr,5));' Warning: fsockopen(): unable to connect to sf.net:8060 (Connection timed out) in Command line code on line 1 bool(false) real 0m5.257s user 0m0.007s sys 0m0.002sRight, same for me : ------------------------- ns55:~# time ./sapi/cli/php -r 'var_dump(fsockopen("sf.net", > 8060,&$errno,&$errstr,5));' -bash: ./sapi/cli/php: No such file or directory real 0m0.004s user 0m0.010s sys 0m0.000s ns55:~# time php -r 'var_dump(fsockopen("sf.net",8060,&$errno,&$errstr,5));' Warning: fsockopen(): unable to connect to sf.net:8060 (Connection timed out) in Command line code on line 1 bool(false) real 0m5.107s user 0m0.080s sys 0m0.020s ns55:~# time php -r 'var_dump(fsockopen("generation.elliptic.fr",8060,&$errno,&$ errstr,5));' resource(4) of type (stream) real 0m0.084s user 0m0.060s sys 0m0.020s ----------------------------------------- Does it mean, the problem is after the fsockopen ? Fsockopen reach host, so it says ok, but dont care if server send something back, then the feof stay stuck as it doesnt find EOF ? Maybe this is it ? in the : while(!feof($scfp)) {$page .= fgets($.... As you see my script, this one hangs in the while loop : <? $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); ?>