ID: 32979 User updated by: mjpph at stardust dot fi Reported By: mjpph at stardust dot fi Status: Open Bug Type: Network related Operating System: Linux (Fedora Core 3) PHP Version: 5CVS-2005-05-08 (dev) Assigned To: wez New Comment:
New info, I was able to get the reproduce code to actually work as it's intended on a Fedora Core 2 machine with PHP 5.0.0RC3 (cgi) (built: Jun 10 2004 16:56:32). Here's strace of it: read(3, "<?\n$c = stream_socket_client(\"tc"..., 8192) = 199 read(3, "", 4096) = 0 read(3, "", 8192) = 0 close(3) = 0 munmap(0x2a97e16000, 4096) = 0 socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP) = 3 close(3) = 0 socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3 fcntl(3, F_GETFL) = 0x2 (flags O_RDWR|O_LARGEFILE) fcntl(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0 connect(3, {sa_family=AF_INET, sin_port=htons(25), sin_addr=inet_addr("83.145.20 0.2")}, 16) = -1 EINPROGRESS (Operation now in progress) select(4, [3], [3], [3], {60, 0}) = 1 (out [3], left {60, 0}) getsockopt(3, SOL_SOCKET, SO_ERROR, [17179869184], [4]) = 0 fcntl(3, F_SETFL, O_RDWR) = 0 select(4, [3], [], [], {0, 5000}) = 0 (Timeout) select(4, [3], [], [], {0, 5000}) = 1 (in [3], left {0, 5000}) select(4, [3], NULL, NULL, {60, 0}) = 1 (in [3], left {60, 0}) at this point the stream_select returns as intended and script ends. The reproduce code DOESN'T work with several machines running Fedora Core 3 by using 5.0.4 as well as with 200505260030 dated snapshot. stream_select simply doesn't give me anything. Platform is Fedora Core 3 x86_64 under dual xeon 3.2ghz (Nocona, EM64T) with kernel 2.6.11-1.14_FC3smp on the machines that don't return stream_select() as it should. Previous Comments: ------------------------------------------------------------------------ [2005-05-26 16:42:54] mjpph at stardust dot fi I used the reproduce code to connect to my own SMTP server, which by using standard socket functions, telnet or any other method instantly outputs the welcome message when I connect. Just add IP+Port to some SMTP server and it'll work for the test. Here's the strace: read(3, "<?\n$c = stream_socket_client(\"tc"..., 8192) = 220 read(3, "", 4096) = 0 read(3, "", 8192) = 0 close(3) = 0 munmap(0x2aaaad2e0000, 4096) = 0 socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP) = 3 close(3) = 0 socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3 fcntl(3, F_GETFL) = 0x2 (flags O_RDWR|O_LARGEFILE) fcntl(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0 connect(3, {sa_family=AF_INET, sin_port=htons(25), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in progress) poll([{fd=3, events=POLLIN|POLLOUT|POLLERR|POLLHUP, revents=POLLOUT}], 1, 60000) = 1 getsockopt(3, SOL_SOCKET, SO_ERROR, "\0\0\0\0", [12884901892]) = 0 fcntl(3, F_SETFL, O_RDWR) = 0 select(4, [3], [], [], {0, 5000}) = 1 (in [3], left {0, 1000}) select(4, [3], [], [], {0, 5000}) = 1 (in [3], left {0, 5000}) select(4, [3], [], [], {0, 5000}) = 1 (in [3], left {0, 5000}) select(4, [3], [], [], {0, 5000}) = 1 (in [3], left {0, 5000}) select(4, [3], [], [], {0, 5000}) = 1 (in [3], left {0, 5000}) .. it continues like this until I kill the script. The stream_select() never returns anything. If I do fgets() instead of the stream_select() it returns the SMTP welcome instantly. ------------------------------------------------------------------------ [2005-05-26 03:05:44] [EMAIL PROTECTED] Worked for me just the other week. You'll need to convince me with a short self-contained test and strace output to prove it. ------------------------------------------------------------------------ [2005-05-09 09:51:34] mjpph at stardust dot fi No I used http only as an examply not thinking that it doesn't actually output anything straight away. I used the example code on several services that output information straight from connect without needing any input from the client. For example port 25 welcome message and several others. Telnet straight away you get a welcome. Use only fgets, you get a welcome. Use the example code, you get nothing. Didn't try anything which actually closes the connection after the output, as this isn't the case with my own implementation either and shouldn't be a requirement anyway. The case is always the same, fgets would get input straight away but stream_select stays dead no matter how many times it loops and waits. Setting the stream to blocking or non-blocking mode has no effect on stream_select's behaviour on this case. The data in the buffer just stays there and stream_select is completely ignorant about it. So, the read wouldn't block (as I know there is data pending), but even despite that stream_select returns 0 changed streams always. So it thinks that read would block, in reality, it doesn't. Partly unrelated: I have this code in a script which also selects stdin. The stdin select works as expected, the stream_socket selecting select doesn't. I had a perfectly working implementation with socket-based functions which stalled at the selects right after I changed to stream_socket-based functions. ------------------------------------------------------------------------ [2005-05-09 01:26:32] [EMAIL PROTECTED] Is the server end of the socket talking http? If not, does it send data to the client immediately upon client connection (without expecting data from the client first)? If not, stream_select() is working precisely as it should. Also note that stream_select() tells you only if a read or write would not block, not whether there actually is data pending. ------------------------------------------------------------------------ [2005-05-08 23:06:40] mjpph at stardust dot fi The issue is the same when using stream_socket_server. stream_socket_accept works as expected, but if you select the socket it always returns 0, even if there is a pending connection which would be returned with stream_socket_accept. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/32979 -- Edit this bug report at http://bugs.php.net/?id=32979&edit=1