企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
Socket扩展是基于流行的BSD sockets,实现了和socket通讯功能的底层接口,它可以和客户端一样当做一个socket服务器。 想了解更通用的客户端socket接口,请看[stream\_socket\_client()](https://www.php.net/manual/zh/function.stream-socket-client.php),[stream\_socket\_server()](https://www.php.net/manual/zh/function.stream-socket-server.php),[fsockopen()](https://www.php.net/manual/zh/function.fsockopen.php), 和[pfsockopen()](https://www.php.net/manual/zh/function.pfsockopen.php)。 使用这些函数时请注意,虽然他们中有很多和C函数同名的,但声明却很可能不同。未避免混淆,请仔细阅读函数描述。 不熟悉socket编程的可以在Unix手册上找到很多有用的信息,网上也有很多C socket编程方面的教程,简单修改一下就可以应用于PHP socket编程。[» Unix Socket FAQ](http://www.unixguide.net/network/socketfaq/)是一个不错的入门。 这里描述的socket函数只是PHP扩展的一部分,编译PHP时必须在**配置**中添加**\--enable-sockets**配置项来启用 在 PHP 5.0.0 开始加入了对 IPv6 的支持。 * [预定义常量](https://www.php.net/manual/zh/sockets.constants.php) * [范例](https://www.php.net/manual/zh/sockets.examples.php) * [Socket Errors](https://www.php.net/manual/zh/sockets.errors.php) * [Socket 函数](https://www.php.net/manual/zh/ref.sockets.php) * [socket\_accept](https://www.php.net/manual/zh/function.socket-accept.php)— Accepts a connection on a socket * [socket\_addrinfo\_bind](https://www.php.net/manual/zh/function.socket-addrinfo-bind.php)— Create and bind to a socket from a given addrinfo * [socket\_addrinfo\_connect](https://www.php.net/manual/zh/function.socket-addrinfo-connect.php)— Create and connect to a socket from a given addrinfo * [socket\_addrinfo\_explain](https://www.php.net/manual/zh/function.socket-addrinfo-explain.php)— Get information about addrinfo * [socket\_addrinfo\_lookup](https://www.php.net/manual/zh/function.socket-addrinfo-lookup.php)— Get array with contents of getaddrinfo about the given hostname * [socket\_bind](https://www.php.net/manual/zh/function.socket-bind.php)— 给套接字绑定名字 * [socket\_clear\_error](https://www.php.net/manual/zh/function.socket-clear-error.php)— 清除套接字或者最后的错误代码上的错误 * [socket\_close](https://www.php.net/manual/zh/function.socket-close.php)— 关闭套接字资源 * [socket\_cmsg\_space](https://www.php.net/manual/zh/function.socket-cmsg-space.php)— Calculate message buffer size * [socket\_connect](https://www.php.net/manual/zh/function.socket-connect.php)— 开启一个套接字连接 * [socket\_create\_listen](https://www.php.net/manual/zh/function.socket-create-listen.php)— Opens a socket on port to accept connections * [socket\_create\_pair](https://www.php.net/manual/zh/function.socket-create-pair.php)— Creates a pair of indistinguishable sockets and stores them in an array * [socket\_create](https://www.php.net/manual/zh/function.socket-create.php)— 创建一个套接字(通讯节点) * [socket\_export\_stream](https://www.php.net/manual/zh/function.socket-export-stream.php)— Export a socket extension resource into a stream that encapsulates a socket * [socket\_get\_option](https://www.php.net/manual/zh/function.socket-get-option.php)— Gets socket options for the socket * [socket\_getopt](https://www.php.net/manual/zh/function.socket-getopt.php)— 别名 socket\_get\_option * [socket\_getpeername](https://www.php.net/manual/zh/function.socket-getpeername.php)— Queries the remote side of the given socket which may either result in host/port or in a Unix filesystem path, dependent on its type * [socket\_getsockname](https://www.php.net/manual/zh/function.socket-getsockname.php)— Queries the local side of the given socket which may either result in host/port or in a Unix filesystem path, dependent on its type * [socket\_import\_stream](https://www.php.net/manual/zh/function.socket-import-stream.php)— Import a stream * [socket\_last\_error](https://www.php.net/manual/zh/function.socket-last-error.php)— Returns the last error on the socket * [socket\_listen](https://www.php.net/manual/zh/function.socket-listen.php)— Listens for a connection on a socket * [socket\_read](https://www.php.net/manual/zh/function.socket-read.php)— Reads a maximum of length bytes from a socket * [socket\_recv](https://www.php.net/manual/zh/function.socket-recv.php)— 从已连接的socket接收数据 * [socket\_recvfrom](https://www.php.net/manual/zh/function.socket-recvfrom.php)— Receives data from a socket whether or not it is connection-oriented * [socket\_recvmsg](https://www.php.net/manual/zh/function.socket-recvmsg.php)— Read a message * [socket\_select](https://www.php.net/manual/zh/function.socket-select.php)— Runs the select() system call on the given arrays of sockets with a specified timeout * [socket\_send](https://www.php.net/manual/zh/function.socket-send.php)— Sends data to a connected socket * [socket\_sendmsg](https://www.php.net/manual/zh/function.socket-sendmsg.php)— Send a message * [socket\_sendto](https://www.php.net/manual/zh/function.socket-sendto.php)— Sends a message to a socket, whether it is connected or not * [socket\_set\_block](https://www.php.net/manual/zh/function.socket-set-block.php)— Sets blocking mode on a socket resource * [socket\_set\_nonblock](https://www.php.net/manual/zh/function.socket-set-nonblock.php)— Sets nonblocking mode for file descriptor fd * [socket\_set\_option](https://www.php.net/manual/zh/function.socket-set-option.php)— Sets socket options for the socket * [socket\_setopt](https://www.php.net/manual/zh/function.socket-setopt.php)— 别名 socket\_set\_option * [socket\_shutdown](https://www.php.net/manual/zh/function.socket-shutdown.php)— Shuts down a socket for receiving, sending, or both * [socket\_strerror](https://www.php.net/manual/zh/function.socket-strerror.php)— Return a string describing a socket error * [socket\_write](https://www.php.net/manual/zh/function.socket-write.php)— Write to a socket * [socket\_wsaprotocol\_info\_export](https://www.php.net/manual/zh/function.socket-wsaprotocol-info-export.php)— Exports the WSAPROTOCOL\_INFO Structure * [socket\_wsaprotocol\_info\_import](https://www.php.net/manual/zh/function.socket-wsaprotocol-info-import.php)— Imports a Socket from another Process * [socket\_wsaprotocol\_info\_release](https://www.php.net/manual/zh/function.socket-wsaprotocol-info-release.php)— Releases an exported WSAPROTOCOL\_INFO Structure