2016-04-28 66 views
1

我已成功在WAMP中安裝了pthreads擴展。PHP 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

命令行PHP通常使用不同的php.ini文件,我懷疑你沒有更新, – 2016-04-28 02:29:03

+0

您好,可以請你建議我在php.ini路徑。 – Naveen

+0

在命令行'php -i'會給你的位置。 – 2016-04-28 03:21:02

回答

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