Re: [PHP] Non-blocking sockets
On Fri, October 27, 2006 3:23 pm, 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. First, to make the initial socket creation/connection not block, you use: http://php.net/ini_set on that one socket connection timeout thingie in php.ini I can't remember right now. *THEN* after you have the socket up and running, you use: http://php.net/socket_set_block At least, that's the way I remember it from the last time I played this game... -- Some people have a gift link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Non-blocking sockets
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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Non-blocking sockets
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Non-blocking sockets
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; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Non-blocking sockets
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Non-blocking sockets
Jochem Maas wrote: 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 I would actually suggest going a bit higher level and using stream_socket_client() instead. Using a stream is much more flexible. See the manual page for the function for some examples. -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] non-blocking sockets + newbie compile question
1) socket_set_blocking()... what the devil's up with this? *I* get socket_set_blocking(): supplied resource is not a valid stream resource, which is obviously a lie, since I can connect to the server program and socket_recv and socket_send both work. I'm using PHP 4.3.1 (cgi) 2) I figured I'd compile the latest CVS snapshot, too, to see if maybe my non-blocking socket will work with that. I've done configure and make, but not make install. What do I do to get my nice new php without replacing the old one? -Josh -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php