php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37517 timeout option of fsockopen seems to be ignored
Submitted: 2006-05-19 11:14 UTC Modified: 2006-06-03 01:00 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:1 (33.3%)
From: gzaboy at hotmai dot com Assigned:
Status: No Feedback Package: *Network Functions
PHP Version: 5.1.4 OS: windows 2003 server
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
45 + 31 = ?
Subscribe to this entry?

 
 [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");


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-26 18:40 UTC] nlopess@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip

I've done a basic test with latest php 5.2 cvs and it works fine. You need to provide more info about your program, like is $server an IP (v4 or v6) or a hostname, the protocol used, etc..
 [2006-05-26 21:12 UTC] brynb at omg-games dot com
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.
 [2006-06-03 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 16:01:29 2024 UTC