- Details
- Created on Wednesday, 06 August 2014 16:40 06 August 2014
Following on 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 through which a client can send requests to a server and receive a response from it 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 socketsocket_bind
— binds a name to a socketsocket_clear_error
— clears an error on the socketsocket_close
— closes a socket resourcesocket_cmsg_space
— calculates the size of the message buffersocket_connect
— starts a connection on a socketsocket_create_listen
— opens a socket on a portsocket_create_pair
— creates a pair of indistinguishable sockets and stores them in an arraysocket_create
— creates a socketsocket_get_option
— gets socket options for the socketsocket_getpeername
— queries the remote side of the given socket;socket_getsockname
— queries the local side of the given socket;socket_import_stream
— imports a streamsocket_last_error
— returns the last error on a socketsocket_listen
— listens for a connection on a socketsocket_read
— reads the maximum length of bytes from a socketsocket_recv
— receives data from a connected socketsocket_recvfrom
— receives data from a socketsocket_recvmsg
— reads a messagesocket_select
— runs the select() system call on the given arrays of sockets with a specified timeoutsocket_send
— sends data to a connected socketsocket_sendmsg
— send a messagesocket_sendto
— sends a message to a socketsocket_set_block
— sets blocking mode on a socket resourcesocket_set_nonblock
— sets a file descriptor to non-blocking modesocket_set_option
— sets socket options for the socketsocket_shutdown
— shuts down a socket for receiving, sending, or bothsocket_strerror
— returns a string, which describes a socket errorsocket_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.
Kind Regards,
Support team