该项目为PHP提供基于POSIX的多线程编程机制。可异步执行任何与定义的用户自定义方法和函数。内建支持同步和同步方法。
要求:
PHP5.3+
ZTSEnabled(ThreadSafety)
PosixThreadsImplementation
示例代码:
<?phpclass AsyncOperation extends Thread { public function __construct($arg){ $this->arg = $arg; } public function run(){ if($this->arg){ printf("Hello %s\n", $this->arg); } }}$thread = new AsyncOperation("World");if($thread->start()) $thread->join();?>
评论