php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14740 fsockopen() won't timeout
Submitted: 2001-12-28 12:31 UTC Modified: 2002-06-10 23:56 UTC
Votes:11
Avg. Score:4.9 ± 0.3
Reproduced:10 of 10 (100.0%)
Same Version:3 (30.0%)
Same OS:5 (50.0%)
From: l0cky at sn0wmen dot fsnet dot co dot uk Assigned: jason (profile)
Status: Closed Package: Sockets related
PHP Version: 4.1.0 OS: Win98 and Win2k
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: l0cky at sn0wmen dot fsnet dot co dot uk
New email:
PHP Version: OS:

 

 [2001-12-28 12:31 UTC] l0cky at sn0wmen dot fsnet dot co dot uk
A simple query to a server with fsockopen() won't timeout if the requested server is down.

$serverquery = fsockopen($host, $port, &$errno, &$errstr, $timeout);

The operation times out first (120 seconds), even if $timeout is as low as 1 second; it works fine if I remove unavailable servers from the query list.  Sometimes the server crashes if I try the function again before the last operation times out.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-12-28 12:33 UTC] l0cky at sn0wmen dot fsnet dot co dot uk
A simple query to a server with fsockopen() won't timeout if the requested server is
down.

$serverquery = fsockopen($host, $port, &$errno, &$errstr, $timeout);

The operation times out first (120 seconds), even if $timeout is as low as 1 second; it
works fine if I remove unavailable servers from the query list.  Sometimes the server
crashes if I try the function again before the last operation times out.
 [2001-12-29 09:20 UTC] l0cky at sn0wmen dot fsnet dot co dot uk
ok to clarify.. seems like this is a common mistake

fsockopen() times out ok if the server doesn't exist.  The problem occurs when the server doesn't understand what is sent to it afterwards and stalls for a reply (ie, if the port is now used by another service).

I'll check the bugs for fwrite(), fgets() etc
 [2002-01-28 12:19 UTC] korpse at p16 dot pub dot ro
well, me too!
os: win xp professional
apache 1.3.22
php 4.1.1 (win32)

the code:

    $fp = fsockopen($hname,139, &$errno, &$errstr,3);
    if(!$fp) echo "$hname is not responding on port 139 ";
    else {
        echo "$hname is alive";
        fclose($fp);
    }

the problem:
    the 3 secs timeout does not work
 [2002-02-11 15:40 UTC] salvag3 at netscape dot net
The timeout doesn't work if the host don't respond on the
requested port :-(

os: linux redhat 7.2
php 4.0.6-7
apache 1.3.20-16
 [2002-02-12 17:13 UTC] jason@php.net
The Win32 code does not set a timeout. The comment at the end refers to there being a problm on linux, which I could not reproduce.

Winsock does support non-blocking IO, but is set up quite differently than BSD sockets.


-Jason
 [2002-03-22 13:49 UTC] jroberts at forumone dot com
System: RedHat Linux
PHP 4.0.6
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 www.krasnapolsky.sr to be slow).  This example took about 3.6 seconds.

CODE:
echo microtime();
echo fsockopen("www.krasnapolsky.sr", 80, &$errno,
&$errstr, 0.2);
echo microtime();
echo "Error Number = $errno, Error String = $errstr";

RESULT:
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.
 [2002-03-22 13:54 UTC] jroberts at forumone dot com
Note on the previous report -- setting an integer for timeout (e.g. 1) does not change the behaviour.  It still takes 3-4 seconds without timing out.
 [2002-05-29 00:33 UTC] jason@php.net
Will work on fix, should be available shortly

-Jason
 [2002-06-10 23:56 UTC] jason@php.net
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at http://snaps.php.net/. In case this was a documentation 
problem, the fix will show up soon at http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.


 [2002-11-06 05:22 UTC] neil at fresh-toast dot uklinux dot net
I can confirm this function stalls when connecting to (remote) firewalled ports, on 4.0.6, it works fine on 4.1.2 and I will suggest my ISP upgrade. Both are redhat/apache.

Question : You refer to the CVS builds having fixed this - which is the minimal build version for this bug to be fixed ?

Thanks for your help.
Neil Smith
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Oct 07 18:01:28 2024 UTC