Skip to Main Content
PHP in a Nutshell
book

PHP in a Nutshell

by Paul Hudson
October 2005
Intermediate to advanced content levelIntermediate to advanced
372 pages
11h 35m
English
O'Reilly Media, Inc.
Content preview from PHP in a Nutshell

Chapter 20. Network Programming

PHP has a number of ways to work over a network: the most common protocols have special functions to make often-used functionality easy, but it is possible to use PHP to write any kind of data over any kind of protocol.

Sockets

While it is out of the scope of this book to go into detail about network infrastructure, you at least need to know what protocols, ports , and sockets are. Protocols are like languages, defining how two computers can talk to each other, and there are hundreds of protocols to perform all varieties of operations—there is a protocol for file transfer (File Transfer Protocol, or FTP), a protocol for transferring web pages (Hypertext Transfer Protocol, or HTTP), a protocol for network management (Simple Network Management Protocol, or SNMP), and many more.

Each protocol has a set of ports that it uses, which are theoretical openings in your computer's Internet connection that clients can connect to. They are numbered 1 to 65535, of which the first 1023 are considered reserved for administrative users. By default, your PC "listens" to no ports, meaning that it ignores all incoming connections. However, if you run a web server, it will open up port 80—this is the port for HTTP, where your web server will listen for requests for web pages. Many of the first 1023 ports are used already, which means if you want to use a port for a new service you have written, it is best that you use a number above 1024.

Sockets are the literal connectors ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP Cookbook

PHP Cookbook

Eric A. Mann
Programming PHP

Programming PHP

Rasmus Lerdorf, Kevin Tatroe
Learning PHP

Learning PHP

David Sklar

Publisher Resources

ISBN: 0596100671Errata Page