Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set a timeout on socket_read

I was wondering how can I set a timeout on a socket_read call? The first time it calls socket_read, it waits till data is sent, and if no data is sent within 5 secs I want to shutdown the connection. Any Help? I already tried SO_RCVTIMEO with no luck.

I'm creating a socket with socket_create() and listening on it for connections, then when connected I listen for the data and then do something with it. When the timeout hits, I want to run socket_shutdown() and then socket_close().

like image 282
James Hartig Avatar asked Dec 23 '08 18:12

James Hartig


2 Answers

this set 5 sec timeout of the socket.

socket_set_option($socket,SOL_SOCKET, SO_RCVTIMEO, array("sec"=>5, "usec"=>0));
like image 155
Nick Avatar answered Nov 04 '22 15:11

Nick


Have you tried socket_set_option with SO_RCVTIMEO

Timeout value for input operations.

like image 12
OIS Avatar answered Nov 04 '22 15:11

OIS