HomePHP Build a Query Processor Class for Networking in PHP 5
Build a Query Processor Class for Networking in PHP 5
Welcome to the first of three tutorials in a series that covers network programming in PHP. In this article you will learn how to use some useful PHP networking functions that will help you perform a variety of common networking tasks. To that end, you will build a simple networking query application in PHP 5.
For many PHP developers, network programming seems to be rather elusive terrain. It becomes even more difficult to navigate when dealing with advanced topics, such as working with low-level sockets or dealing with the numerous and intimidating features of a specific network protocol.
However, things aren't as hard as they look at first glance. As with everything in software development (and particularly when developing Internet-related applications), it's possible to dive into the network programming area in a friendly way, without the need to get completely obfuscated by the buzzwords that surround the topic, or without suffering premature aging, all because you can't get that socket opened on a particular TCP port.
Now, and seriously speaking, when you start using PHP to develop your Web applications, sooner or later you'll be faced with solving some specific issues related to network programming. Actually, this makes a lot of sense, considering the fact that the Web is a big part (and certainly the most friendly one) of the Internet, which is after all a giant network.
For this reason, and others that you may want to add from your own experience, this series will be focused exclusively on building a simple -- yet useful -- networking query application in PHP 5. It will expose some useful methods, handy for performing a few common networking tasks, such as converting host names to their IP addresses and vice versa, searching for DNS records, scanning TCP ports, finding the port number of a given service, and more.
The networking query application that I plan to build will be encapsulated within a single PHP 5 class, but you can easily modify its complete source code in order to work with PHP 4. As I said before, this application should be considered a practical introduction to using many PHP built-in functions included in the corresponding PHP network library, so if you want to learn how to use these functions, this series might help you to start quickly including them in your own applications.
Now, with the preliminaries out of our way, it's time to start coding the network query class. Let's do it together!