Using fsockopen()

The fopen() function is one way to access Web pages, but a more sophisticated method would be to use fsockopen(). This function opens sockets—a channel of communication—on a server.

$fp = fsockopen ("", 80, &$errno, &$errstr, 30);

You use fsockopen() to establish a file pointer as you would use fopen(). The parameters the function takes are the URL, the port (here, 80), an error number variable, an error string variable, and the timeout. The last three arguments are optional. In layman's terms, a port is the door through which different protocols (methods of communication) go. For Web pages, the port is normally 80. The error number and string variables are interesting in that they are not really sent to ...

Get PHP Advanced for the World Wide Web: Visual QuickPro Guide now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.