PHP 8.5.0 Alpha 1 available for testing

socket_getsockname

(PHP 4 >= 4.1.0, PHP 5, PHP 7, PHP 8)

socket_getsocknameInterroga el socket local

Descripción

socket_getsockname(Socket $socket, string &$address, int &$port = null): bool

Nota: socket_getsockname() no debe ser utilizada con los sockets AF_UNIX creados con socket_connect(). Solo los sockets tras una llamada a socket_bind() devolverán valores lógicos.

Parámetros

socket

Una instancia de Socket creada por socket_create() o socket_accept().

address

Si el socket socket es de tipo AF_INET, o AF_INET6, socket_getsockname() devolverá la dirección IP local, en notación numérica (e.g. 127.0.0.1 o fe80::1) en el parámetro address, y si el parámetro opcional port está presente, también devolverá el puerto de la comunicación establecida.

Si el socket socket es de tipo AF_UNIX, socket_getsockname() devolverá la ruta en el sistema de archivos (e.g. /var/run/daemon.sock) en el parámetro address.

port

Si se proporciona, este deberá ser el puerto asociado a la dirección.

Valores devueltos

Devuelve true en caso de éxito o false en caso de error. socket_getsockname() también puede devolver false si el tipo del socket no es ni AF_INET, ni AF_INET6, ni AF_UNIX, en cuyo caso el último código de error socket no es modificado.

Historial de cambios

Versión Descripción
8.0.0 socket is a Socket instance now; previously, it was a resource.

Ver también

add a note

User Contributed Notes 1 note

up
1
CXJ
10 years ago
Curiously, getsockname() works for socket_create() and socket_create_pair() Unix-domain (AF_UNIX) sockets if one calls socket_bind() after creation to name the formerly anonymous socket(s).

Using a socket_bind() call also results in a file system "file" (socket, first character 's' in an "ls -l" listing) being created with the given name. Such a "file" will need to be removed explicitly, as closing the socket will not remove it.
To Top