mirror of
https://github.com/danog/ext-uv.git
synced 2024-11-26 20:14:47 +01:00
add examples
This commit is contained in:
parent
d51ca2eee1
commit
055afdb520
19
examples/idle.php
Normal file
19
examples/idle.php
Normal 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
25
examples/request.php
Normal 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
7
examples/run_once.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
$idle = uv_idle_init();
|
||||
uv_idle_start($idle, function(){
|
||||
echo "Hello";
|
||||
});
|
||||
|
||||
uv_run_once();
|
Loading…
Reference in New Issue
Block a user