php.net |  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
Votes:2
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
Have you experienced this issue?
Rate the importance of this bug to you:

 [2007-09-03 23:57 UTC] sy at yalcin dot us
Description:
------------
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

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

1188857394
1188857426
bool(false)

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

php -a
Interactive mode enabled

<?php
echo time()."\n";
$f = fsockopen('10.20.30.40', 80, $tmp, $tmp, 2);
echo time()."\n";
var_dump($f);

1188857495
1188857497
bool(false)

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

<?php
echo time()."\n";
$f = fsockopen('www.google.com', 80, $tmp, $tmp, 2);
echo time()."\n";
var_dump($f);

1188857665
1188857681
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 \
--with-apxs2

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.



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-04 09:57 UTC] jani@php.net
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] jani@php.net
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 11:01:24 2021 UTC