PHP pthreads无法从命令行界面运行

时间:2016-04-28 02:19:27

标签: php wamp

我已在WAMP中成功安装了pthreads扩展名。

我从浏览器运行Notifications.php时收到输出。

但是,当我从命令行运行相同的代码时,它会向我显示错误。

我在以下文件夹中复制了 pthreadVC2.dll

D:\wamp\bin\php\php5.5.12
D:\wamp\bin\apache\apache2.4.9\bin

FROM Browser FROM Command Line

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);
}
?>

1 个答案:

答案 0 :(得分:0)

我得到了这个问题的解决方案。

使用以下命令找出在命令行中加载的配置文件(php.ini)。

> php -i

在我的情况下,文件路径是:

D:\wamp\bin\php\php5.5.12\php.ini

所以,我使用下面的行启用了php_pthreads.dll扩展名。

extension = php_pthreads.dll

它可能对你有帮助。

enter image description here