|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-05-19 11:14 UTC] gzaboy at hotmai dot com
Description:
------------
the timeout option of fsockopen seems to be ignored below code,if remote host has no responed,the error information:"Error" would not display:
Reproduce code:
---------------
$h = fsockopen($server,80,$errno,$errstr,5);
if($h){
fwrite($h,$post);
while(!feof($h)){
$str .= fgets($h,127);
}
fclose($h);
return $str;
}else{
die("Error");
}
Expected result:
----------------
die("Error");
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 00:00:02 2025 UTC |
I'm having the same problem, even after installing 5.2. $serverip = "192.168.0.12"; $fp = fsockopen($serverip, 80, $errno, $errstr, 3); if(!$fp) { print "CONNECTION FAILED"; return 0; } fputs($fp,$httpheader); //get the response $result=""; while (!feof($fp)) $result .= fread($fp,32000); fclose($fp); print $result; so, the function either times out (30 second script execution limit) or $result ends up as a blank string. the initial fsockopen call should fail, because i'm contacting an ip at which there's no http server (in fact, it's a 2nd computer sitting RIGHT NEXT TO ME and i'm switching apache on and off to test this thing). the $serverip variable IS an ipv4 address. i'm basically sending an http request through tcp (i've even tried prefixing "tcp://" to the ip, with no variance in result). note that all of this code works perfectly when the apache server is enabled... it's just when it's disabled that i get these results.