add examples

This commit is contained in:
Shuhei Tanuma 2012-05-29 01:31:18 +09:00
parent d51ca2eee1
commit 055afdb520
3 changed files with 51 additions and 0 deletions

19
examples/idle.php Normal file
View File

@ -0,0 +1,19 @@
<?php
$loop = uv_default_loop();
$idle = uv_idle_init();
$i = 0;
uv_idle_start($idle, function($stat) use (&$i, $idle, $loop){
echo "count: {$i}" . PHP_EOL;
$i++;
if ($i > 3) {
uv_idle_stop($idle);
uv_unref($loop);
}
sleep(1);
});
uv_run();
echo "finished";

25
examples/request.php Normal file
View File

@ -0,0 +1,25 @@
<?php
$tcp = uv_tcp_init();
$address = uv_ip4_addr("173.194.38.65","80");
uv_tcp_connect($tcp, $address, function($stat, $client){
$request = <<<EOF
GET / HTTP/1.0
Host: google.com
EOF;
uv_write($client,$request,function($stat, $client){
if ($stat == 0) {
uv_read_start($client,function($buffer, $client){
var_dump($buffer);
uv_close($client,function(){
});
});
} else {
uv_close($client,function(){});
}
});
});
uv_run();

7
examples/run_once.php Normal file
View File

@ -0,0 +1,7 @@
<?php
$idle = uv_idle_init();
uv_idle_start($idle, function(){
echo "Hello";
});
uv_run_once();