mirror of
https://github.com/danog/ext-uv.git
synced 2024-11-27 04:24:45 +01:00
adjust request example. and fix read_start_cb. it might called mutiple times.
This commit is contained in:
parent
4bb3eea336
commit
a241a55602
@ -1,23 +1,40 @@
|
|||||||
<?php
|
<?php
|
||||||
$tcp = uv_tcp_init();
|
|
||||||
$address = uv_ip4_addr("173.194.38.65","80");
|
|
||||||
|
|
||||||
uv_tcp_connect($tcp, $address, function($stat, $client){
|
$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){
|
||||||
$request = <<<EOF
|
$request = <<<EOF
|
||||||
GET / HTTP/1.0
|
GET {$path} HTTP/1.0
|
||||||
Host: google.com
|
Host: {$host}
|
||||||
|
|
||||||
|
|
||||||
EOF;
|
EOF;
|
||||||
uv_write($client,$request,function($stat, $client){
|
uv_write($client,$request,function($stat, $client){
|
||||||
if ($stat == 0) {
|
if ($stat == 0) {
|
||||||
uv_read_start($client,function($buffer, $client){
|
uv_read_start($client,function($buffer, $client){
|
||||||
var_dump($buffer);
|
var_dump($buffer);
|
||||||
|
//uv_close($client);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
uv_close($client);
|
uv_close($client);
|
||||||
});
|
}
|
||||||
} else {
|
});
|
||||||
uv_close($client);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
1
php_uv.c
1
php_uv.c
@ -445,6 +445,7 @@ static void php_uv_read_cb(uv_stream_t* handle, ssize_t nread, uv_buf_t buf)
|
|||||||
php_uv_do_callback(&retval_ptr, uv->read_cb, params, 2 TSRMLS_CC);
|
php_uv_do_callback(&retval_ptr, uv->read_cb, params, 2 TSRMLS_CC);
|
||||||
|
|
||||||
zval_ptr_dtor(&buffer);
|
zval_ptr_dtor(&buffer);
|
||||||
|
Z_TYPE_P(rsc) = IS_NULL;
|
||||||
zval_ptr_dtor(&rsc);
|
zval_ptr_dtor(&rsc);
|
||||||
zval_ptr_dtor(&retval_ptr);
|
zval_ptr_dtor(&retval_ptr);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user