PHP socket extension enabled on all our hosting servers
On the basis of our customers’ requests, we have installed the PHP socket extension on all our web hosting servers to provide PHP socket programmers with a low-level interface for network communication purposes.
PHP sockets are fundamental endpoints that allow clients and servers to communicate in a networked environment. They create an end-to-end communication channel where a client sends requests to a server, which receives them and responds back in return.
For instance, when you type www.google.com in your web browser, it opens a socket (usually on port 80) and connects to the web server to deliver the page to you. The same holds true for any chat client like gTalk or Skype, for example.
Up until now, we have supported functions like fsockopen() for network communication purposes. With the installation of the PHP socket extension, developers will be able to use an array of more complicated functions that will offer them a greater flexibility in establishing a socket-based client-server communication over TCP/IP and in building simple, PHP-based, client-server network applications.
Here is a list of the main low-level-interface functions for creating and manipulating socket communications that are now supported 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 size of the message buffer
- socket_connect — starts a connection on a socket
- socket_create_listen — opens a socket on a port
- socket_create_pair — creates a pair of indistinguishable sockets and stores them in an array
- socket_create — creates a socket
- socket_get_option — gets socket options for the socket
- socket_getpeername — queries the remote side of the given socket;
- socket_getsockname — queries the local side of the given socket;
- socket_import_stream — imports a stream
- socket_last_error — returns the last error on a socket
- socket_listen — listens for a connection on a socket
- socket_read — reads the maximum length of bytes from a socket
- socket_recv — receives data from a connected socket
- socket_recvfrom — receives data from a socket
- socket_recvmsg — reads a message
- socket_select — runs the select() system call on the given arrays of sockets with a specified timeout
- socket_send — sends data to a connected socket
- socket_sendmsg — send a message
- socket_sendto — sends a message to a socket
- socket_set_block — sets blocking mode on a socket resource
- socket_set_nonblock — sets a file descriptor to non-blocking mode
- socket_set_option — sets socket options for the socket
- socket_shutdown — shuts down a socket for receiving, sending, or both
- socket_strerror — returns a string, which describes a socket error
- socket_write — writes to a socket
Those of you who are unfamiliar with socket programming can find a lot of useful information on the Unix Socket FAQ page. With slight modifications, this information is fully applicable to socket programming in PHP.
Originally published Wednesday, August 6th, 2014 at 4:40 pm, updated November 19, 2015 and is filed under Web Hosting Platform.
Tags: web hosting