2016-04-28 2 views
1

Я успешно установил расширение pthreads в WAMP.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, я подозреваю, что вы не обновляли, что –

+0

привет, пожалуйста, вы можете предложить мне путь php.ini. – Naveen

+0

в командной строке 'php -i' предоставит вам местоположение. –

ответ

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