The PHP socket extension has been activated on all of our hosting servers

August 6, 2014
In response to customer requests, we have implemented the PHP socket extension across all our web hosting servers.

This enhancement grants PHP socket programmers access to a low-level interface for effective network communication purposes.

PHP sockets serve as fundamental endpoints facilitating communication between clients and servers within a networked environment. They create a direct communication channel where clients forward requests to servers, and the servers, in turn, process and reply to these requests.

For instance, when you input "www.google.com" in your web browser, a socket is initiated, typically on port 80, to establish a connection with the web server and retrieve the requested webpage. This principle is applicable to various communication platforms like gTalk or Skype.

Historically, we have supported functions such as fsockopen() to address network communication requirements. With the integration of the PHP socket extension, developers gain access to a diverse range of more intricate functions, offering increased flexibility in forming client-server communication via sockets over TCP/IP. This also aids in constructing basic PHP-driven client-server network applications.

Highlighted below is a compilation of the main low-level interface functions for creating and manipulating socket communications, now accessible on our servers:

  • socket_accept: Accepts a connection on a socket
  • socket_bind: Binds a name to a socket
  • socket_clear_error: Clears an error on the socket
  • socket_close: Closes a socket resource
  • socket_cmsg_space: Calculates the message buffer size
  • socket_connect: Initiates a connection on a socket
  • socket_create_listen: Opens a socket on a designated port
  • socket_create_pair: Creates a matched pair of indistinguishable sockets and stores them in an array
  • socket_create: Generates a socket
  • socket_get_option: Retrieves socket options for the socket
  • socket_getpeername: Queries the remote side of the provided socket
  • socket_getsockname: Queries the local side of the given socket
  • socket_import_stream: Imports a stream
  • socket_last_error: Returns the most recent error on a socket
  • socket_listen: Listens for a connection on a socket
  • socket_read: Reads a specified maximum length of bytes from a socket
  • socket_recv: Receives data from a connected socket
  • socket_recvfrom: Collects data from a socket
  • socket_recvmsg: Reads a message
  • socket_select: Executes the select() system call on designated socket arrays with a specified timeout
  • socket_send: Dispatches data to a connected socket
  • socket_sendmsg: Dispatches a message
  • socket_sendto: Dispatches a message to a socket
  • socket_set_block: Configures blocking mode on a socket resource
  • socket_set_nonblock: Switches a file descriptor to non-blocking mode
  • socket_set_option: Establishes socket options for the socket
  • socket_shutdown: Shuts down a socket for receiving, sending, or both
  • socket_strerror: Produces a descriptive string for a socket error
  • socket_write: Writes to a socket

For those unfamiliar with socket programming, the Unix Socket FAQ page contains invaluable information, which can be applied with slight modifications to PHP socket programming.