简体   繁体   English

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

[英]PHP pthreads is not working from Command Line Interface

I have successfully installed pthreads extension in WAMP. 我在WAMP中成功安装了pthreads扩展。

I received output when I run the Notifications.php from browser. 我从浏览器运行Notifications.php时收到输出。

But, when I run the same code from command line it showing me an error. 但是,当我从命令行运行相同的代码时,它向我显示错误。

I had copied the pthreadVC2.dll in below folders. 我在下面的文件夹中复制了pthreadVC2.dll

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

从浏览器 从命令行

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

I got a solution for this question. 我得到了这个问题的解决方案。

use the below command to find out which configuration file (php.ini) is loading in command line. 使用以下命令找出在命令行中加载的配置文件(php.ini)。

> php -i

In my case the file path is: 在我的例子中,文件路径是:

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

So, I enabled the php_pthreads.dll extension using below line. 所以,我使用下面的行启用了php_pthreads.dll扩展。

extension = php_pthreads.dll

It might help you. 它可能对你有帮助。

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM