# php-uv [![Build Status](https://secure.travis-ci.org/bwoebi/php-uv.png)](http://travis-ci.org/bwoebi/php-uv) Interface to libuv for php. # Install ## \*nix ```` git clone https://github.com/bwoebi/php-uv.git cd php-uv phpize ./configure make make install # add `extension=uv.so` to your php.ini ```` ## Windows Windows builds for stable PHP versions are available [from PECL](https://pecl.php.net/package/uv). # Examples see examples and tests directory. ````php 3) { uv_idle_stop($idle); } sleep(1); }); uv_run(); ```` ### void uv_idle_stop(resource $idle) ##### *Description* stop idle callback. ##### *Parameters* *resource $idle*: uv_idle resource. ##### *Return Value* *long result*: ##### *Example* ````php 3) { uv_idle_stop($idle); } sleep(1); }); uv_run(); ```` ### void uv_getaddrinfo(resource $loop, callable $callback, string $node, string $service, array $hints) ### 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_stdio_new(zval $fd, long $flags) ### resource uv_spawn(resource $loop, string $command, array $args, array $stdio, string $cwd, array $env = array(), callable $callback [,long $flags, array $options]) ### 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(long $value) ##### *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) ##### *Description* execute callbacks in another thread (requires Thread Safe enabled PHP) ### 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