Manuel PHP
Précédent |  | Suivant

# socket_create

(PHP 4 >= 4.1.0)

socket_create -- Create a socket (endpoint for communication)

## Description

resource socket_create ( int domain, int type, int protocol)

Avertissement
Cette fonction est EXPERIMENTALE. Cela signifie que le comportement de cette fonction, son nom et concrètement, TOUT ce qui est documenté ici peut changer dans un futur proche, SANS PREAVIS! Soyez-en conscient, et utilisez cette fonction à vos risques et périls.

Creates a communication endpoint (a socket), and returns a socket resource.

The `domain` parameter sets the domain (protocol family) to be used for communication. Currently, `AF_INET` and `AF_UNIX` are understood. `AF_INET` is typical used for internet based communication. `AF_UNIX` uses pathnames to identify sockets and can therefore only be used for local communication (which is faster, on the other hand).

The `type` parameter selects the socket type. This is one of `SOCK_STREAM`, `SOCK_DGRAM`, `SOCK_SEQPACKET`, `SOCK_RAW`, `SOCK_RDM`, or `SOCK_PACKET`. The two most common types are `SOCK_DGRAM` for `UDP` (connectionless) communication and `SOCK_STREAM` for `TCP` communication.

`protocol` sets the protocol which is either `SOL_UDP` or `SOL_TCP`.

Returns a socket resource on success, or `FALSE` on error. The actual error code can be retrieved by calling socket_last_error(). This error code may be passed to socket_strerror() to get a textual explanation of the error.

For more information on the usage of socket_create(), as well as on the meanings of the various parameters, see the Unix man page socket (2).

> Note : If an invalid `domain` or `type` is given, socket_create() defaults to `AF_INET` and `SOCK_STREAM` respectively and additionally emits an `E_WARNING` message.

See also socket_accept(), socket_bind(), socket_connect(), socket_listen(), socket_last_error(), and socket_strerror().

Précédent | Sommaire | Suivant
socket_create_pair | Niveau supérieur | socket_get_option