downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

socket_read> <socket_last_error
[edit] Last updated: Fri, 17 May 2013

view this page in

socket_listen

(PHP 4 >= 4.1.0, PHP 5)

socket_listenEscucha una conexión sobre un socket

Descripción

bool socket_listen ( resource $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 backlog para 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 backlog depende mayormente en la plataforma subyacente. En Linux, se trunca de forma silenciosa a SOMAXCONN. 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



add a note add a note User Contributed Notes socket_listen - [2 notes]
up
1
Karuna Govind (karuna.kgx gmail)
4 years ago
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.
up
-2
lewislp at yahoo dot com
7 years ago
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).

 
show source | credits | stats | sitemap | contact | advertising | mirror sites