pthread在PHP中不起作用 [英] pthread not working in php
问题描述
我已经从
I have downloaded the PHP Pthreads dll file from http://windows.php.net/downloads/pecl/releases/pthreads/ and enabled it in php.ini as below:
extension=pthreadVC2.dll
extension=php_pthreads.dll
我使用了以下示例代码:
I have used below sample code:
<?php
class AsyncOperation extends Thread
{
public function __construct($arg){
$this->arg = $arg;
}
public function run(){
if($this->arg){
printf("Hello %s\n", $this->arg);
}
}
}
$thread = new AsyncOperation("World");
if($thread->start())
$thread->join();
当我执行代码时,出现以下错误:
when i executed the code i get the following error:
致命错误:在C:\ htdocs \ threads \ AsyncOperation.php中找不到类'Thread' 第2行调用堆栈:0.0008 333464 1. {main}() C:\ htdocs \ threads \ AsyncOperation.php:0
Fatal error: Class 'Thread' not found in C:\htdocs\threads\AsyncOperation.php on line 2 Call Stack: 0.0008 333464 1. {main}() C:\htdocs\threads\AsyncOperation.php:0
推荐答案
这里有两个问题:
1)首先必须正确查找dll文件的位置. dll文件应放置如下:
1) First have to look for dll files location correctly. dll files should be placed as below:
C:\PHP5\pthreadVC2.dll
C:\PHP5\ext\php_pthreads.dll
,并且在php.ini文件中,仅应将php_pthreads.dll启用为
and in php.ini file only php_pthreads.dll should be enabled as
extension=php_pthreads.dll
2)必须查找PHP和dll文件的版本.
2) Have to look for Versions of PHP and dll file.
我的PHP是VC6构建版本,使用的dll文件是VC9.这就是为什么未安装模块的原因.我通过使用" php -m "来了解这种区别.
My PHP is VC6 build and dll file used is VC9. Thats why module didn't get installed. I came to know this difference by using "php -m".
由于没有VC6版本的dll文件,因此我使用了VC9版本的PHP和pthreads,并且程序运行正常.
Since there is no VC6 build of dll file, I have used VC9 build of PHP and used pthreads and the program is working perfectly.
注意:以上两种解决方案解决了我的问题.但是,如果仍然出现错误,请检查是否启用了调试器xdebug或zend.禁用它们,然后重试.
Note:The above two solutions solved my problems. But if you are still getting errors check if you have debuggers enabled xdebug or zend. Disable them and try again.
这篇关于pthread在PHP中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!