Beware, when using this function within a loop (i.e. a demon with a socket). The socket_accept(), for example, emits a warning each time there is no incoming connection available to be read. My php error log file got huge in a matter of seconds, eventually crashing the server.
Of course, i used the @ before the function to take care of that problem.
[EDITOR: One can (and should) use socket_select to detect a new connection on a socket (it's a "readable" event)]
socket_set_nonblock
(PHP 4 >= 4.1.0, PHP 5)
socket_set_nonblock — Attiva la modalità "nonblocking" per il descrittore di file fd
Descrizione
bool socket_set_nonblock
( resource
$socket
)Avviso
Questa funzione è SPERIMENTALE. Ovvero, il comportamento di questa funzione, il nome di questa funzione, in definitiva tutto ciò che è documentato qui può cambiare nei futuri rilasci del PHP senza preavviso. Siete avvisati, l'uso di questa funzione è a vostro rischio.
La funzione socket_set_nonblock() imposta il flag O_NONBLOCK
per il socket indicato dal parametro socket.
Example #1 Esempio di uso di socket_set_nonblock()
<?php
$port = 9090;
if (!$socket = socket_create_listen($port)) {
echo socket_strerror(socket_last_error());
}
if (!socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1)) {
echo socket_strerror(socket_last_error());
}
if (!socket_set_nonblock($socket)) {
echo socket_strerror(socket_last_error());
}
?>
Restituisce TRUE in caso di successo, FALSE in caso di fallimento.
Vedere anche socket_set_block() e socket_set_option()
kpobococ at gmail dot com ¶
3 years ago
