|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16261 fsockopen() does not allow milisecond timeouts
Submitted: 2002-03-25 09:55 UTC Modified: 2002-07-23 16:49 UTC
Avg. Score:4.7 ± 0.7
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:3 (75.0%)
From: jroberts at forumone dot com Assigned:
Status: Closed Package: Sockets related
PHP Version: 4.3-dev OS: Linux
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 !
Your email address:
Solve the problem:
23 + 16 = ?
Subscribe to this entry?

 [2002-03-25 09:55 UTC] jroberts at forumone dot com
I'm specifying a timeout of 0.2 seconds, but the fsockopen() function is taking as long as 3-4 seconds with slow domains (I know to be slow).  This example took about 3.6 seconds.

echo microtime();
echo fsockopen("", 80, &$errno, &$errstr, 0.2);
echo microtime();
echo "Error Number = $errno, Error String = $errstr";

0.39859300 1016822517
Resource id #1
0.04482100 1016822521
Error Number = 0, Error String = 

So the socket is opened -- it just took way longer than I intended to allow it.  Setting the timeout to an integer (e.g. 1) does not work either (although the documentation says it can be of type float).

I reported this previously under bug 14740, but that thread was related to win 98 and 2k, where the timeout is not expected to work.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-03-25 09:58 UTC] jroberts at forumone dot com
BTW, socket_set_timeout is working fine for me after the socket has been opened.  It's the failure to timeout on the actual fsockopen() that is causing issues.
 [2002-07-15 09:46 UTC]
This behavior does not actually exist in the version you report. The test domain you are using is slow on the DNS lookup, which does not count against the timeout.

The current development branch does not allow subsecond timeouts, and as such I am modifying this bug to apply.

 [2002-07-15 12:34 UTC] jroberts at forumone dot com
Thanks Jason.  Would it be possible/desireable to include the time for DNS lookup in the timeout period?  I'm using sockets to request headers for remote files (PDF, etc.) to display size/type in a distributed library.  In cases where I'm showing 10-20 files per page, a delay of more than 0.5 seconds or so each is major problem -- regardless of whether it's caused by DNS lookup or response from the actual server.  In those cases I'd rather just show a "filesize unknown" message rather than waiting an indeterminate amount of time for the content-length header.
 [2002-07-23 16:49 UTC]
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at In case this was a documentation 
problem, the fix will show up soon at
In case this was a website problem, the change will show
up on the site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.

fsockopen now behaives as specified.
As far as the DNS queries go, there is no way to currently achieve that behavior on all platforms. I would recommend using gethostbyname, and passing the ip directly to fsockopen, this will cause you to take the dns hit once.

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon Aug 15 14:05:45 2022 UTC