To change the maximum allowed backlog by your system (*nix machines only), first you need to find the variable for this limit:
sudo sysctl -a | grep somaxconn
On ubuntu boxes, it returns net.core.somaxconn (you need to look for the 'somaxconn' variable, the full name will vary across different systems).
Update this to a large number as follows:
sudo sysctl -w net.core.somaxconn=1024
This will work straight away. no restart required.
socket_listen
(PHP 4 >= 4.1.0, PHP 5)
socket_listen — Attende una richiesta di connessione su un socket
Descrizione
$socket
[, int $backlog
] )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.
Una volta creato il socket socket tramite
la funzione socket_create(), ed eseguito il bind ad un nome
con socket_bind(), lo si può mettere in ascolto di
eventuali richieste di connessione su socket.
Nota:
Il numero massimo, passato con il parametro
backlogdipende fortemente dalla piattaforma sottostante. Su Linux questo viene troncato, senza avvisare, aSOMAXCONN. Su Win32, se viene passata la costanteSOMAXCONN, il servizio sottostante responsabile dei socket valorizzabacklogal massimo valore ragionevole. Non esiste un metodo standard per determinare il reale valore massimo su questa piattaforma.
La funzione socket_listen() è disponibile solo per i socket di tipo SOCK_STREAM o SOCK_SEQPACKET.
Restituisce TRUE in caso di successo, FALSE in caso di fallimento. Il codice di errore può essere recuperato con
socket_last_error(). Questo codice può essere passato a
socket_strerror() per ottenere una spiegazione
dell'errore.
Vedere anche socket_accept(), socket_bind(), socket_connect(), socket_create() e socket_strerror().
socket_listen() cannot be used for UDP communications as discussed below.
In addition, the example below discusses UDP connections, which only exist if the application manages them through a state table (the OS does not create a UDP connection upon receiving a datagram). Having a function named socket_connect() that determines the remote IP and port only confuses the matter by giving the indication of some sort of connection handshake between two hosts. Rather, socket_connect() only specifies the remote IP and port used by subsequent socket_send() calls. You can achieve the same effect by skipping socket_connect() altogether and specifying the remote IP and port in socket_sendto() calls.
If you find yourself writing a connection-based protocol on top of UDP, consider using TCP. If your application requires streaming data of some sort, use TCP to manage connections and control messages, and UDP to handle the streaming data (H.323 is an example of a suite of TCP and UDP protocols working in conjunction).
