Reputation: 5805
I start the following server:
<?php
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_bind($socket, 'localhost', 9000) or die("Failed: socket_bind()");
socket_listen($socket, 20) or die("Failed: socket_listen()");
$client = socket_accept($socket);
socket_set_option($client, SOL_SOCKET, SO_RCVTIMEO, array('sec'=>1, 'usec'=>0));
socket_set_option($client, SOL_SOCKET, SO_SNDTIMEO, array('sec'=>1, 'usec'=>0));
while(1) {
$read = array($client);
$write = $except = null;
socket_select($read,$write,$except,1);
}
When I try connect to this server with telnet localhost 9000
it does not exit after a second, despite I have set 1 sec timeout.
PHP 7.0.11 on Linux. There is a similar problem with PHP 5.6.21 on FreeBSD
Why does it not work?
Note: In this example I try to decrease the timeout. In my real problem I need to increase it to a few hours or maybe few days.
Upvotes: 1
Views: 202
Reputation: 123260
There is no reason it should exit. As far as I understand your code:
Upvotes: 1