2012-05-28 18:31:18 +02:00
|
|
|
<?php
|
|
|
|
|
2012-06-03 17:37:45 +02:00
|
|
|
$url = "http://yahoo.co.jp/";
|
|
|
|
|
|
|
|
$parts = parse_url($url);
|
|
|
|
$domain = $parts['host'];
|
|
|
|
$path = $parts['path'] . '?' . $parts['query'];
|
|
|
|
|
|
|
|
$uv = uv_ares_init_options(uv_default_loop(), array(
|
|
|
|
"servers" => array(
|
|
|
|
"8.8.8.8"
|
|
|
|
),
|
|
|
|
"port"=>53
|
|
|
|
),null);
|
|
|
|
|
|
|
|
ares_gethostbyname($uv,$domain, AF_INET, function($name, $addr) use ($path, $host){
|
|
|
|
$a = array_shift($addr);
|
|
|
|
$address = uv_ip4_addr($a,"80");
|
|
|
|
$tcp = uv_tcp_init();
|
|
|
|
|
|
|
|
uv_tcp_connect($tcp, $address, function($stat, $client) use ($path, $host){
|
2012-05-28 18:31:18 +02:00
|
|
|
$request = <<<EOF
|
2012-06-03 17:37:45 +02:00
|
|
|
GET {$path} HTTP/1.0
|
|
|
|
Host: {$host}
|
2012-05-28 18:31:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
EOF;
|
2012-06-10 15:38:18 +02:00
|
|
|
echo $request;
|
|
|
|
var_dump($client);
|
2012-06-03 17:37:45 +02:00
|
|
|
uv_write($client,$request,function($stat, $client){
|
|
|
|
if ($stat == 0) {
|
|
|
|
uv_read_start($client,function($buffer, $client){
|
|
|
|
var_dump($buffer);
|
|
|
|
//uv_close($client);
|
|
|
|
});
|
|
|
|
} else {
|
2012-05-29 01:00:17 +02:00
|
|
|
uv_close($client);
|
2012-06-03 17:37:45 +02:00
|
|
|
}
|
|
|
|
});
|
2012-05-28 18:31:18 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
uv_run();
|