Asynchronous socket connection timing issue.

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hello everyone here.

This is my first post in this newsgroup, I hope I won't be to much
off-topic. Feel free to redirect me to any better group.

I am getting strange timing issues when failing to asynchronously connect
sockets on closed or filtered ports, but I'm quite unsure if this is a PHP
issue or my misunderstanding, as it seems that socket streams only wrap
around <sys/socket.h>.

I'm running the latest Windows PHP build downloaded yesterday,
running from the command line without any configuration changed from
default. My code is at with results at

Connecting to an open port seems consistent between synchronous and
asynchronous sockets. Opening the socket is instantaneous, connection
establishes in 0.17 seconds, and closing is fast.

Connecting to a filtered port ends up with a socket timeout, but
asynchronous socket closing blocks for 0.5 second which is quite huge. No
network transfer was captured by Wireshark apart from the initial SYN

Connecting to a closed port with a synchronous socket times out, with
several retries being sent after the server explicitly refused the
connection with a RST ACK. Why doesn't it simply break after the first try ?

Connecting to a closed port with an asynchronous socket takes the time of a
single try, marking the stream as having had an except in stream_select
after RST ACK was received. But here again, fclose()-ing the resource hangs
for 0.5 second.

Why is that an explicitly refused synchronous connection retries until
timeout ? Why doesn't it cancel instantaneously ?

Why is that closing a failed asynchronous socket takes so much time ? It is
really losing a lot of asynchronous' interest if it hangs that long ?

Note that if I don't explicitly fclose() the resources of failed
asynchronous sockets, the same 0.5 seconds lag appears at the end of the
script execution for each one. I guess PHP cleanly frees resources at
shutdown, but it can reach several seconds when several sockets have failed.

Is there another way than fclose() to clear asynchronous sockets ?

Thank you for any advice.

Nicolas Le Gland  

Re: Asynchronous socket connection timing issue.

Quoted text here. Click to load it

As this temporary hosting expired after 24h, here are both code and log :

Re: Asynchronous socket connection timing issue.

Having succeeded in writing the same code using the BSD sockets extension  
without any such delay, I filled a bug concerning stream implementation.

Feel free to reply there.

Nicolas Le Gland  

Site Timeline