php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44864 STREAM_CLIENT_ASYNC_CONNECT does does not work
Submitted: 2008-04-29 21:25 UTC Modified: 2008-05-10 01:00 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: fhoenig at kargo dot com Assigned: fb-req-jani (profile)
Status: No Feedback Package: Streams related
PHP Version: 5.2.5 OS: FreeBSD 7.0 / AMD64
Private report: No CVE-ID: None
 [2008-04-29 21:25 UTC] fhoenig at kargo dot com
Description:
------------
The below code only works with sleeping in between stream_socket_client() and the first IO on the socket. No error though.
Works on FreeBSD 6.2 and linux as well as OSX. Just not on Freebsd 7.0. was installed through ports with default options.

What changed in freebsd 7 that could cause that? Fix through sysctl option maybe?

Reproduce code:
---------------
$fp = stream_socket_client("tcp://www.google.com:80", $errno, $errstr, 0, STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT);

//sleep(1); <=== works only with sleep uncommented.

if (!$fp) {
    echo "$errstr ($errno)<br />\n";
} else {
    fwrite($fp, "GET / HTTP/1.0\r\nHost: www.example.com\r\nAccept: */*\r\n\r\n");
    while (!feof($fp)) {

        echo fgets($fp, 1024);
    }
    fclose($fp);
}



Expected result:
----------------
The html output from www.google.com/


Actual result:
--------------
Locks up after fwrite and never reads anything from the socket. No error. 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-29 23:56 UTC] fhoenig at kargo dot com
Actually I cased down the problem a bit further.

socket_select under these conditions is not waiting even is the tv_sec is set to NULL (in which case it should wait infinitely)

instead of sleep, put: $num_changed_streams = stream_select($rfd, $wfd, $efd, NULL);

something is wrong with sockets here...
 [2008-04-30 16:16 UTC] fhoenig at kargo dot com
Yes and it does even more unpredictable things. It seems like I get the bytes I write to the socket back on the reads... I need to look more into it though. I just found that the problem does not exist on freebsd 7.0/i386. So it has to do with 64-bit land.
 [2008-04-30 16:43 UTC] fhoenig at kargo dot com
The select issue seems indeed fixed in the 5.2-latest. However, since the sockets extension was built as a SO, I still need to try whether it's related to that.
 [2008-05-10 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-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 12 20:01:27 2024 UTC