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 ("www.DMCinsights.com", 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 books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.