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 — Escucha una conexión sobre un socket
Descripción
$socket
[, int $backlog = 0
] )
Después de que el socket socket haya sido creado
usando socket_create() y vinculado a un nombre con
socket_bind(), se le puede indicar que escuche conexiones
entrantes sobre socket.
socket_listen() sólo es aplicable a sockets de
tipo SOCK_STREAM o
SOCK_SEQPACKET.
Parámetros
-
socket -
Un recurso socket válido creado con socket_create().
-
backlog -
Se pondrán en cola un máximo de conexiones entrantes
backlogpara su procesamiento. Si una petición de conexión llega con la cola llena, el cliente puede recibir un error con una indicación de ECONNREFUSED, o, si el protocolo subyacente soporta retransmisiones, la petición puede ser ignorada, por lo que este reintento puede surtir efecto.Nota:
El número máximo pasado al parámtro
backlogdepende mayormente en la plataforma subyacente. En Linux, se trunca de forma silenciosa aSOMAXCONN. En win32, Si se pasóSOMAXCONN, el proveedor del servicio responsable del socket establecerá el backlog a un valor máximo razonable. No existe una disposicón estándar para encontrar el valor del backlog real en esta plataforma.
Valores devueltos
Devuelve TRUE en caso de éxito o FALSE en caso de error. El código de error real se puede recuperar
llamando a socket_last_error(). Este código se puede
pasar a socket_strerror() para obtener una explicación textual del
error.
Ver también
- socket_accept() - Acepta una conexión de un socket
- socket_bind() - Vincula un nombre a un socket
- socket_connect() - Inicia una conexión sobre un socket
- socket_create() - Crear un socket (extremo de comunicación)
- socket_strerror() - Devuelve una cadena que describe un error de socket
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).
