[PHP-BUG] Bug #71251 [NEW]: Blocking TCP socket connection does not timeout

[email protected] ("gohanman at gmail dot com")
Newsgroups php.bugs
Message-ID <[email protected]>
From:             gohanman at gmail dot com
Operating system: Windows 10
PHP version:      7.0.1
Package:          Sockets related
Bug Type:         Bug
Bug description:Blocking TCP socket connection does not timeout 

Description:
------------
I'm trying to set a connection timeout on a TCP port. I specifically
want to verify whether a remote service is alive. If the host does not
respond within the specified timeout, I want to mark it as down and
continue with execution. If you happen to be running something on port
15674 substitute any closed port. I *want* the connection to fail in a
predictable way.

In PHP 5.3 - 5.6, socket_connect blocks for roughly one second and then
returns false. In PHP 7, socket_connect blocks for infinity as far as I
can tell. The longest I've let it run so far is about 15 minutes but its
clearly ignoring every built in execution limit. Restarting Apache is
the only thing that halts the script's execution.

I'm using php.ini-production with the following modules enabled:
sockets, opcache, curl, gettext, intl, mysqli, pdo_mysql, openssl, and
xsl. Other than enabling modules I haven't made any changes to the
config.

Apache is 2.4.18 (Apache Lounge build). Both PHP and Apache are x86. The
same code does work as expected on the same machine in PHP 5.3 - PHP 5.6
so I don't think it's strictly a Windows 10 problem. I'm running the
older PHP versions with different, older VC9 and VC11 Apache builds of
course.

Test script:
---------------
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_option($sock, SOL_SOCKET, SO_SNDTIMEO, array('sec' => 1,
'usec' => 0)); 
socket_set_block($sock);
$test = @socket_connect($sock,'localhost',15674);
socket_close($sock);
echo "Done";

Expected result:
----------------
$test gets boolean value true or false without more or less one second
(with reasonable allowance for whatever precision the underlying system
can actually provide).

Actual result:
--------------
socket_connect blocks forever

-- 
Edit bug report at https://bugs.php.net/bug.php?id=71251&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=71251&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=71251&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=71251&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=71251&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=71251&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=71251&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=71251&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=71251&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=71251&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=71251&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=71251&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=71251&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=71251&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71251&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=71251&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=71251&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=71251&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71251&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=71251&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=71251&r=mysqlcfg
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.