Making a Network Connection

So far, we have had it easy. This is because PHP makes working with a Web page on a remote server as simple as opening a file on your own system. Sometimes, though, you need to exercise a little more control over a network connection or acquire more information about it.

You can make a connection to an Internet server with fsockopen(), which requires a hostname or an IP address, a port number, and two empty variables. The empty variables you pass to fsockopen() are populated to provide more information about the connection attempt should it fail. You can also pass fsockopen() an optional timeout integer, which determines how long fsockopen() will wait (in seconds) before giving up on a connection. If the connection ...

Get Sams Teach Yourself PHP in 24 Hours, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.