|  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
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: fhoenig at kargo dot com
New email:
PHP Version: OS:


 [2008-04-29 21:25 UTC] fhoenig at kargo dot com
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://", $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:\r\nAccept: */*\r\n\r\n");
    while (!feof($fp)) {

        echo fgets($fp, 1024);

Expected result:
The html output from

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


Add a Patch

Pull Requests

Add a Pull Request


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 May 30 05:01:31 2024 UTC