|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42537 fsockopen() hangs
Submitted: 2007-09-03 23:57 UTC Modified: 2007-09-12 01:00 UTC
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: sy at yalcin dot us Assigned:
Status: No Feedback Package: URL related
PHP Version: 5.2.4 OS: RHEL 4
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: sy at yalcin dot us
New email:
PHP Version: OS:


 [2007-09-03 23:57 UTC] sy at yalcin dot us
Firewall blocking or slowness in DNS causes fsockopen() hang, much more than it should.This should return in 2 seconds. But it does not:

somedomain.localsite is not valid.
php -a
Interactive mode enabled

echo time()."\n";
$f = fsockopen('somedomain.localsite', 80, $tmp, $tmp, 2);
echo time()."\n";


Try with a unreachable IP, it returns as expected: ( is not valid)

php -a
Interactive mode enabled

echo time()."\n";
$f = fsockopen('', 80, $tmp, $tmp, 2);
echo time()."\n";


This can be a firewall/dns issue. There is a very complicated firewall installed here, which I don't know details yet.

It seems some packages are received, so that function does not time out as expected. However it does not return because it waits for some other packages.

Following is a google connection, it connects, but still not within 2 seconds. Socket handler is returned as if there is no delay!

php -a
Interactive mode enabled

echo time()."\n";
$f = fsockopen('', 80, $tmp, $tmp, 2);
echo time()."\n";

resource(1) of type (stream)

Reproduce code:
Tested this with PHP 5.2.3 and does the same problem.

PHP is compiled with this:
./configure \
--with-config-file-path=/etc \
--enable-bcmath \
--with-bz2 \
--enable-calendar \
--enable-ftp \
--with-gettext \
--with-iconv \
--enable-mbstring=all \
--with-mysql \
--with-openssl \
--enable-sockets \
--enable-wddx \
--with-zlib \
--with-xmlrpc \
--enable-soap \
--enable-pcntl \
--enable-memory-limit \
--enable-force-cgi-redirect \
--disable-debug \
--enable-cgi \
--enable-fastcgi \
--enable-sysvsem \
--enable-sysvshm \
--enable-sysvmsg \
--enable-shmop \

Expected result:
I expect that fsockopen() will return back witin 2 seconds:

1) with FALSE return, means unsuccessful,
2) with a valid socket handler.

Any delay more than 2 seconds is not acceptable.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-04 09:57 UTC]
Works fine for me. And there is a firewall also between my connection.
I think it's your DNS being slow..try debugging this using gdb to see where it hangs.

 [2007-09-04 18:47 UTC] sy at yalcin dot us
Ok, I will try using gdb to see. It may take a few days to give you feedback.
Would strace dump work?
 [2007-09-04 22:12 UTC]
Keep this in feedback state until you have the feedback.
Regarding strace, I'd rather see GDB backtrace where it hangs. But if you're unable to get that, maybe strace can give us some clue.

I don't know why you changed the summary nor what it was originally.
Please don't change that anymore. :)
 [2007-09-12 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-2021 The PHP Group
All rights reserved.
Last updated: Wed Jul 28 10:01:24 2021 UTC