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

search for in the

socket_read> <socket_last_error
Last updated: Fri, 14 Aug 2009

view this page in

socket_listen

(PHP 4 >= 4.1.0, PHP 5)

socket_listenAttend une connexion sur une socket

Description

bool socket_listen ( resource $socket [, int $backlog= 0 ] )

Une fois que la socket socket a été créée avec la fonction socket_create() et liée à un nom avec la fonction socket_bind(), elle peut être mise en attente de connexion entrante.

socket_listen() ne fonctionne qu'avec des sockets de type SOCK_STREAM et SOCK_SEQPACKET.

Liste de paramètres

socket

Une ressource de socket valide, créée par la fonction socket_create().

backlog

Un nombre maximum de backlog connexions seront mises en attente de traitement. Si une demande de connexion arrive et que la queue est pleine, le client recevra une erreur indiquant ECONNREFUSED, ou, si le protocole de support accepte les retransmissions, la requête sera ignorée pour que les tentatives ultérieures finissent par réussir.

Note: Le nombre maximum passé dans le paramètre backlog dépend essentiellement de la plate-forme de support. Sur Linux, il est tronqué automatiquement à SOMAXCONN. Sous Windows, si la constante SOMAXCONN est passée, le service responsable des sockets choisira une valeur maximum raisonnable. Il n'y a pas de méthode pour deviner la valeur réellement choisie.

Valeurs de retour

Cette fonction retourne TRUE en cas de succès, FALSE en cas d'échec. Le code d'erreur généré peut être obtenu en appelant la fonction socket_last_error(). Ce code d'erreur peut être passé à la fonction socket_strerror() pour obtenir un message d'erreur humainement lisible.

Voir aussi



add a note add a note User Contributed Notes
socket_listen
Karuna Govind (karuna.kgx gmail)
15-Jul-2008 11:10
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.
lewislp at yahoo dot com
30-Aug-2005 07:13
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).

socket_read> <socket_last_error
Last updated: Fri, 14 Aug 2009
 
 
show source | credits | sitemap | contact | advertising | mirror sites