php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62890 default_socket_timeout=-1 causes connection to timeout
Submitted: 2012-08-22 10:25 UTC Modified: 2020-06-09 10:46 UTC
Votes:7
Avg. Score:3.9 ± 1.5
Reproduced:5 of 5 (100.0%)
Same Version:2 (40.0%)
Same OS:2 (40.0%)
From: fallingdust at gmail dot com Assigned: cmb (profile)
Status: Closed Package: OpenSSL related
PHP Version: 7.3 OS: Mac Lion 10.7.4
Private report: No CVE-ID: None
 [2012-08-22 10:25 UTC] fallingdust at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/filesystem.configuration
---

php.ini configuration:

allow_url_fopen = On
allow_url_include = Off
;from="john@doe.com"
;user_agent="PHP"
default_socket_timeout = 60
;auto_detect_line_endings = Off

Test script:
---------------
php -r 'ini_set("default_socket_timeout", -1); echo file_get_contents("http://www.google.com");'

Expected result:
----------------
print the html of google page.

Actual result:
--------------
PHP Warning:  file_get_contents(http://www.google.com): failed to open stream: 
Operation now in progress in Command line code on line 1
PHP Stack trace:
PHP   1. {main}() Command line code:0
PHP   2. file_get_contents() Command line code:1

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-26 16:52 UTC] pembo at neonerve dot com
This appears to only be an issue on Macs. When using it on Windows / Linux it performs as expected.
 [2018-07-01 18:04 UTC] jose dot nobile at gmail dot com
It is reproducible on Linux (Centos 6.9/CloudLinux). I need set it to -1 because Redis:brpoplpush timeout each minute (The default socket timeout value is 60 secs), but file_get_contents fail with file_get_contents(): SSL: Handshake timed out, file_get_contents(): Failed to enable crypto, file_get_contents(https://someExampledomain.tld): failed to open stream: operation failed. I have to set ['http' => ['timeout' => 10]] via stream_context_create to make it works.
Tested in PHP 7.2.7
 [2020-06-09 09:23 UTC] cmb@php.net
-PHP Version: 5.3.16 +PHP Version: 7.3
 [2020-06-09 09:23 UTC] cmb@php.net
I can confirm that with default_socket_timeout=-1,
file_get_contents('http://www.google.com') succeeds, but
file_get_contents('https://www.google.com') fails.

Apparently, some code paths ignore negative timeouts by special
casing them[1], and others don't.

[1] <https://github.com/php/php-src/blob/PHP-7.3/main/network.c#L1243>
 [2020-06-09 10:38 UTC] cmb@php.net
-Summary: Set default_socket_timeout to -1 causes not able to connect +Summary: default_socket_timeout=-1 causes connection to timeout -Package: Sockets related +Package: OpenSSL related
 [2020-06-09 10:46 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2020-06-09 11:38 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #62890: default_socket_timeout=-1 causes connection to timeout
On GitHub:  https://github.com/php/php-src/pull/5693
Patch:      https://github.com/php/php-src/pull/5693.patch
 [2020-06-09 14:49 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=eadd98070662f0c56d7138bcb2a42d397c11f6e4
Log: Fix #62890: default_socket_timeout=-1 causes connection to timeout
 [2020-06-09 14:49 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Aug 11 01:01:25 2020 UTC