ptaskPHP 的協(xié)程擴(kuò)展
ptask 是 PHP 的協(xié)程擴(kuò)展。
使用這個(gè)擴(kuò)展,使得 PHP 可以像 Python 和 Lua 一樣使用協(xié)程。
安裝:
$ git clone https://github.com/liexusong/ptask $ cd ptask/libtask $ make $ sudo make install $ cd ../ext $ phpize $ ./configure --with-php-config=path-to-php-config $ make $ sudo make install
修改php.ini,添加extension=ptask.so。
使用:
<?php
function handler($arg)
{
for ($i = 0; $i < 1000; $i++) {
echo $arg, ": ", $i, "\n";
ptask_yield();
}
}
ptask_create("handler", "handler1");
ptask_create("handler", "handler2");
ptask_run();評(píng)論
圖片
表情
