[英]PHP pthreads is not working from Command Line Interface
我在WAMP中成功安装了pthreads扩展。
我从浏览器运行Notifications.php时收到输出。
但是,当我从命令行运行相同的代码时,它向我显示错误。
我在下面的文件夹中复制了pthreadVC2.dll 。
D:\wamp\bin\php\php5.5.12
D:\wamp\bin\apache\apache2.4.9\bin
Notifications.php
<?php
/*
* In this example, you will see how to make a process and thread synchronize with each other
*/
/* this is just so reading the logic makes sense */
function do_some_work($m) {
usleep($m);
}
class ExampleThread extends Thread {
/*
* always set defaults for threaded objects in constructors
* note: using entry level defaults (at the class declaration)
* does not work as expected in pthreads, this is because
* handlers are not invoked to set defaults at the class level
*/
public function __construct() {
}
public function run() {
while (!$this->isWaiting()) {
/* the process is not yet waiting */
/* in the real world, this would indicate
that the process is still working */
/* in the real world, you might have work to do here */
echo ".";
}
echo "\n";
/* always synchronize before calling notify/wait */
$this->synchronized(function($me) {
/* there's no harm in notifying when no one is waiting */
/* better that you notify no one than deadlock in any case */
$me->notify();
}, $this);
}
}
/* construct the new thread */
$t = new ExampleThread();
/* start the new thread */
if ($t->start()) {
printf("\nProcess Working ...\n");
do_some_work(1000);
/* synchronize in order to call wait */
$t->synchronized(function($me) {
/*
* note: do not stay synchronized for longer than you must
* this is to reduce contention for the lock
* associated with the threads internal state
*/
printf("\nProcess Waiting ...\n");
$me->wait();
printf("Process Done ...\n");
}, $t);
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.