Socket Programming.Retrieving Webpages. Help please
Posted: Sun Jan 11, 2004 6:07 pm
I am trying to write a program that needs to connect to multiple webpages. I currently use file() or file_get_contents() in the script.
To increase the speed of this script I'm planning on using socket_set_nonblock. So that I'm able to retrieve multiple pages at the same time.
I've been reading about socket programming with PHP. Seeing how it seems as though using those functions will be the only way I'll be able to use socket_set_unblock.
However, I have not been able to find many Good resources discussing the SPECIFICS on HTTP commands and replies. I have also been unable to retrieve a full web page with socket_read().
Any help would be appreciated. Especially on retrieving a webpage with socket_read() etc.
Thanks in advance.
Sample Code below
To increase the speed of this script I'm planning on using socket_set_nonblock. So that I'm able to retrieve multiple pages at the same time.
I've been reading about socket programming with PHP. Seeing how it seems as though using those functions will be the only way I'll be able to use socket_set_unblock.
However, I have not been able to find many Good resources discussing the SPECIFICS on HTTP commands and replies. I have also been unable to retrieve a full web page with socket_read().
Any help would be appreciated. Especially on retrieving a webpage with socket_read() etc.
Thanks in advance.
Sample Code below
Code: Select all
$host = "www.google.com";
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could Not Create Socket\n");
socket_connect($socket, $host, 80) or die("Could Not Connect to $host");
$output = "GET / HTTP/1.1\r\n";
$output .= "Host: http://www.google.com\r\n";
$output .= "Connection: Close\r\n\r\n";
socket_write($socket, $output, strlen($output) ) or die("Could Not write to socket");
$data = socket_read($socket, 4096) ;
socket_close($socket);
print $data;
?>