Hudzilla.org - the homepage of Paul Hudson
Contents > Wish List | Report Bug | About Me ]

15     Networks

This is NOT the latest copy of this book; click here for the latest version.

The Internet is really just one big network, albeit the largest and most convoluted one ever created, and there are a variety of different protocols that allow communication. The most common protocol is HTTP, followed by FTP, but there are literally dozens of others, each with their own specific purpose.

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.

The topics covered in this chapter are:

  • What sockets are, and basic socket use

  • How to use sockets outside of HTTP

  • How to create a basic server using PHP

  • Creating a web server

  • Helpful network-related functions

  • HTTP-specific and FTP-specific functions

  • The Curl library


Chapter contents

15.1. Sockets
15.1.1. Sockets are files: fsockopen()
15.1.2. Making a simple search engine
15.1.3. Sockets aren't all about HTTP
15.1.4. Sockets can be servers: socket_create_listen(), socket_accept(), socket_write(), socket_read(), and socket_close()
15.1.5. Sockets can be powerful
15.2. Domain resolution functions: dns_check_record(), dns_get_mx(), and dns_get_record()
15.3. Host and IP resolution: gethostbyaddr(), gethostbyname(), and gethostbynamel()
15.4. HTTP
15.4.1. Sending custom headers: header() and headers_sent()
15.4.2. Reading queued headers: headers_list()
15.4.3. Authentication over HTTP
15.4.4. Dynamic authentication
15.5. Sending mail: mail()
15.5.1. MIME types: mime_content_type()
15.5.2. Easier mail sending with PEAR::Mail
15.5.3. Sending mixed-type messages with PEAR::Mail_Mime
15.5.4. Sending attachments (at last!)
15.6. Reading mail
15.6.1. Opening a mailbox: imap_open() and imap_close()
15.6.2. Reading message information: imap_headers() and imap_header()
15.6.3. Reading message contents: imap_num_msg() and imap_body()
15.7. Dealing with MIME-encoded messages: imap_fetchbody()
15.8. Mail management: imap_sort(), imap_delete(), imap_undelete(), imap_expunge(), imap_mailboxmsginfo(), and imap_last_error()
15.9. Transferring files over FTP: ftp_connect(), ftp_login(), ftp_pasv(), ftp_chdir(), ftp_get(), and ftp_close()
15.9.1. Other helpful FTP functions: ftp_put(), ftp_systype(), ftp_rename(), ftp_mkdir(), and ftp_rmdir()
15.10. Curl
15.10.1. Installing Curl
15.10.2. Your first Curl scripts: curl_init(), curl_setopt(), curl_exec(), curl_close()
15.10.3. The abridged list of Curl options
15.10.4. Debugging Curl
15.11. Custom data stream handling
15.11.1. The Morse code stream: stream_wrapper_register()
15.12. Summary
15.13. Exercises
15.14. Further reading
15.15. Next chapter



<< 14.6 Next chapter   15.1 Sockets >>
Table of Contents
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.



My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!



Top-right shadow
 
Bottom-left shadow Bottom shadow

Comments from other readers
vinska - 24 Jul 2008

Vinska was here

A PHP Usefr - 24 Jul 2008

cvhfgh



Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.

If you are reporting an error in the content, please tell me directly.

Your name/email address:
Your comment:
 
Now, in order to verify that you're a real person, please answer this simple question: what is seven plus four?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow