socket_set_nonblock

(PHP 4 >= 4.1.0, PHP 5, PHP 7, PHP 8)

socket_set_nonblockAttiva la modalità "nonblocking" per il descrittore di file fd

Descrizione

socket_set_nonblock(resource $socket): bool
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()

add a note add a note

User Contributed Notes 1 note

up
6
kpobococ at gmail dot com
14 years ago
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)]
To Top