Re: Non-blocking sockets
| From: | Jochem Maas | Date: | Sat, 28 Oct 2006 01:43:52 +0000 |
| Subject: | Re: Non-blocking sockets | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-243781@lists.php.net to get a copy of this message | ||
Eric wrote:
> Stut wrote:
>> Eric wrote:
>>> When I create a socket/stream that connects to a news sever and try
>>> to recv data from the socket when there is nothing there (Like if the
>>> server sends one line and I call recv twice) the socket freezes. I
>>> assume this is because using socket_create or fsockopen creates a
>>> blocking TCP/Stream socket by default. When I call
>>> socket_set_nonblock() and the socket_connect I get "A non-blocking
>>> operation could not be completed immediately". Could someone show me
>>> exactly how to create a non-blocking TCP/Stream socket? Thanks in
>>> advance.
>>
>> I may be wrong but I think you need to set the socket non-blocking
>> after the connect. You cannot do a non-blocking connect.
>>
>> -Stut
> Then the socket recv doesnt work. Gives me "Unable read from socket".
>
> $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
> socket_connect($socket,"news.csh.rit.edu",119);
> socket_set_nonblock($socket);
> socket_recv($socket,$buf,1024,0);
> echo $buf;
I *think* you need to be looking here:
http://php.net/manual/en/function.socket-select.php
>