Retrieving a Website Using Sockets
<?php
$address = "127.0.0.1";
$port = 80;
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_connect($socket, $address, $port);
socket_write($socket, "GET /index.php HTTP/1.0\n\n");
$result = "";
while($read = socket_read($socket, 1024)) {
$result .= $read;
}
echo "Result received: '$result'\n";
socket_close($socket);
?>
Related examples in the same category