HomePHP Developing an Extensible TCP Server with Sockets in PHP
Developing an Extensible TCP Server with Sockets in PHP
Are you interested in learning how to manipulate low-level sockets in PHP? Your search has finished. This is the second part of the series “Handling sockets in PHP,” and hopefully you’ll find in it valuable material regarding the creation and manipulation of sockets with PHP, in conjunction with numerous illustrative hands-on examples that will help you build socket servers in a few easy steps.
For those who haven't read my first tutorial yet, let me briefly recapitulate the topics that I treated previously. To begin with, I explained how to create a low-level socket in PHP and perform some key operations with it, such as pushing in and pulling out data streams.
Aside from covering some key points related to handling sockets, I set up a complete example, which focused on developing a simple TCP server and the corresponding client. In this way I demonstrated how they can communicate with each other, introducing some kind of basic processing on the traveling data.
After testing the sample TCP server that I developed in the first article, surely you'll realize the excellent capabilities that come with PHP for handling sockets, and more generally for addressing common issues associated with network programming. Going deeper into socket manipulation, building end-to-end communication channels as part of an application allows you to understand much better the logic behind the relationship between server and clients. Considering this crucial concept, programming sockets in PHP can be a useful experience.
Now, focusing specifically on this second article of the series, I'll go one step further in the manipulation of low-level sockets, and show you how to expand the TCP server that was constructed previously, in order to provide it with the ability to attend to multiple requests coming from the same client. Hopefully, this experience will help you to get a more intimate knowledge of socket handling in PHP.
With the preliminaries out of the way, let's get started.