I wrote those script to get HTTP url content, and it works , but it can't
read the whole content of the page.
Blocked on "while ($out = socket_read($socket, 1024)) ".
browser show the processbar all the time , and the page is not completed
display,
If I press ESC key to cancel the request , the resource of page show that :
the target URL were not read completed .
next codes never been executed .
Why socket_read blocked?
Additional : The network and URL are absolute valid all the time . the size
of target page is about 30k bits .
script :
<?
header("Content-type: text/html; charset=UTF-8");
error_reporting(E_ALL);
echo "<h2>TCP/IP Connection</h2>\n<pre>";
$service_port = 80;
$host = "10.1.1.144";
$file = "/index.aspx";
$address = gethostbyname('10.1.1.144');
/* Create a TCP/IP socket. */
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket < 0)
{
echo "socket_create() failed.\n reason: " . socket_strerror($socket) .
"\n";
} else
{
echo "OK.\n";
}
echo "try connect to '$address' : '$service_port'...";
$result = socket_connect($socket, $address, $service_port);
if ($result < 0)
{
echo "socket_connect() failed.\n reason: ($result) " .
socket_strerror($result) . "\n";
} else {
echo "OK.\n";
}
//$in = "HEAD / HTTP/1.1\r\n";
$in = '';
$in .= "GET {$file} HTTP/1.1\r\n";
$in .= "Accept: text/html\r\n";
$in .= "Accept-Language: zh-cn\r\n";
//$in .= "Accept-Encoding: gzip, deflate\r\n";
$in .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET
CLR 2.0.50727)\r\n";
$in .= "Host: {$host}\r\n";
$in .= "Cache-Control: no-cache\r\n";
$in .= "Connection: Keep-Alive\r\n\r\n";
echo "send HTTP HEAD request...\n{$in}";
socket_write($socket, $in, strlen($in));
echo "OK.\n";
echo "read response:---------------\n\n<textarea>";
$len = 0;
$out= '';
while ($out = socket_read($socket, 1024)) //
-------------------------------wait for too long time .!!!!!!!!!
{
$len += strlen($out);
echo $out;
}
echo "</textarea>";
echo "close socket ...";
socket_close($socket);
echo "OK.\n\n";
?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php