# php-uv [![Build Status](https://secure.travis-ci.org/chobie/php-uv.png)](http://travis-ci.org/chobie/php-uv) interface to libuv for php (experimental). also supports http-parser. # Experimental This extension is experimental, its functions may change their names or move to extension all together so do not rely to much on them you have been warned! # Install ```` git clone https://github.com/chobie/php-uv.git --recursive cd php-uv (cd libuv && make) phpize ./configure make make install # add `extension=uv.so` to your php.ini ```` # Examples see examples and tests directory. ```` 3) { uv_idle_stop($idle); } sleep(1); }); uv_run(); ```` ### void uv_getaddrinfo(resource $loop, callable $callback, string $node, string $service, array $hints) ### void uv_idle_stop(resource $idle) ##### *Description* stop idle callback. ##### *Parameters* *resource $idle*: uv_idle resource. ##### *Return Value* *void*: ##### *Example* ````php 3) { uv_idle_stop($idle); } sleep(1); }); uv_run(); ```` ### resource uv_tcp_init([resource $loop]) ##### *Description* create a tcp socket. ##### *Parameters* *resource $loop*: loop resource or null. if not specified loop resource then use uv_default_loop resource. ##### *Return Value* *resource php_uv*: uv resource which initialized for tcp. ##### *Example* ````php // float(1.7421875) // [1]=> // float(1.427734375) // [2]=> // float(1.3955078125) //} ```` ##### *Note* returns array on windows box. (does not support load average on windows) ### double uv_uptime(void) ##### *Description* returns current uptime. ##### *Parameters* ##### *Return Value* *long $uptime*: ##### *Example* ````php // array(3) { // ["model"]=> // string(13) "MacBookPro8,2" // ["speed"]=> // int(2200) // ["times"]=> // array(5) { // ["sys"]=> // int(69952140) // ["user"]=> // int(38153450) // ["idle"]=> // int(776709120) // ["irq"]=> // int(0) // ["nice"]=> // int(0) // } // }... ```` ### array uv_interface_addresses(void) ### resource uv_spawn(resource $loop, string $command, array $args, array $context, callable $callback) ##### *Todo* * fix context keys and values. ### void uv_process_kill(resource $handle, long $signal) ##### *Description* send signal to specified uv process resource. ##### *Parameters* *resource $handle*: uv resource handle (process) *long $signal*: ##### *Return Value* *void*: ##### *Example* ### void uv_kill(long $pid, long $signal) ##### *Description* send signal to specified pid. ##### *Parameters* *long $pid*: process id *long $signal*: ##### *Return Value* *void*: ##### *Example* ### bool uv_chdir(string $directory) ##### *Description* change working directory. ##### *Parameters* *string $directory*: ##### *Return Value* *bool *: ##### *Example* ### resource uv_rwlock_init(void) ##### *Description* initialize rwlock resource ##### *Parameters* ##### *Return Value* *resource $rwlock*: returns uv rwlock resource ##### *Example* ### uv_rwlock_rdlock(resource $handle) ##### *Description* set read lock ##### *Parameters* *resource $handle*: uv resource handle (uv rwlock) ##### *Return Value* *void *: ##### *Example* ### bool uv_rwlock_tryrdlock(resource $handle) ##### *TODO* * implemnt this correctly ### void uv_rwlock_rdunlock(resource $handle) ##### *Description* unlock read lock ##### *Parameters* *resource $handle*: uv resource handle (uv rwlock) ##### *Return Value* *void*: ##### *Example* ### uv_rwlock_wrlock(resource $handle) ##### *Description* set write lock ##### *Parameters* *resource $handle*: uv resource handle (uv rwlock) ##### *Return Value* *void *: ##### *Example* ### uv_rwlock_trywrlock(resource $handle) ##### *TODO* * implement this correctly ### uv_rwlock_wrunlock(resource $handle) ##### *Description* unlock write lock ##### *Parameters* *resource $handle*: uv resource handle (uv rwlock) ##### *Return Value* *void*: ##### *Example* ### uv_lock uv_mutex_init(void) ##### *Description* initialize mutex resource ##### *Parameters* ##### *Return Value* *resource $uv_mutex*: uv mutex resource ##### *Example* ### void uv_mutex_lock(uv_lock $lock) ##### *Description* lock mutex ##### *Parameters* *resource $handle*: uv resource handle (uv mutex) ##### *Return Value* *void*: ##### *Example* ### bool uv_mutex_trylock(uv_lock $lock) ##### *TODO* * implement this correctly ### uv_lock uv_sem_init(void) ##### *Description* initialize semaphore resource ##### *Parameters* ##### *Return Value* *resource $uv_sem*: ##### *Example* ### void uv_sem_post(uv_lock $sem) ##### *Description* post semaphore ##### *Parameters* *resource $handle*: uv resource handle (uv sem) ##### *Return Value* *void*: ##### *Example* ### void uv_sem_wait(uv_lock $sem) ##### *Todo* * implemnt this correctly ### void uv_sem_trywait(uv_lock $sem) ##### *Todo* * implment this correctly ### resource uv_prepare_init(resource $loop) ##### *Description* initialize prepare resource ##### *Parameters* *resource $loop*: uv loop handle ##### *Return Value* *resource $uv_prepare*: ##### *Example* ````php 3) { uv_idle_stop($idle); } sleep(1); }); uv_check_start($check, function($check, $status){ echo "Hello"; uv_check_stop($check); }); uv_run(); ```` ### void uv_check_stop(resource $handle) ##### *Description* stop check callback ##### *Parameters* *resource $check*: uv resource handle (check) ##### *Return Value* *void *: ### resource uv_async_init(resource $loop, callable $callback) ##### *Description* setup async callback ##### *Parameters* *resource $loop*: uv loop resource *callback $callback*: ##### *Return Value* *resource *: uv async resource ##### *Example* ### void uv_async_send(resource $handle) ##### *Description* send async callback immidiately ##### *Parameters* *resource $handle*: uv async handle ##### *Return Value* *void*: ##### *Example* ### void uv_queue_work(resource $loop, callable $callback, callable $after_callback) ### resource uv_fs_open(resource $loop, string $path, long $flag, long $mode, callable $callback) ##### *Description* open specified file ##### *Parameters* *resource $loop*: uv_loop resource. *string $path*: file path *long $flag*: file flag. this should be UV::O_RDONLY and some constants flag. *long $mode*: mode flag. this should be UV::S_IRWXU and some mode flag. *callable $calback*: this callback parameter expects (resource $stream) ##### *Return Value* *void*: ##### *Example* ````php // array(8) { // ["Host"]=> // string(10) "chobie.net" // ["User-Agent"]=> // string(81) "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:12.0) Gecko/20100101 Firefox/12.0" // ["Accept-Language"]=> // string(14) "en-us,en;q=0.5" // ["Accept-Encoding"]=> // string(13) "gzip, deflate" // ["Connection"]=> // string(10) "keep-alive" // ["Referer"]=> // string(18) "http://chobie.net/" // ["Cookie"]=> // string(9) "key=value" // ["Cache-Control"]=> // string(9) "max-age=0" // } // ["QUERY_STRING"]=> // string(35) "/img/http-parser.png?key=value#frag" // ["path"]=> // string(20) "/img/http-parser.png" // ["query"]=> // string(9) "key=value" // ["fragment"]=> // string(4) "frag" // ["REQUEST_METHOD"]=> // string(3) "GET" //} } ````