PHP pthreads:致命错误:找不到类“线程"
我在网络服务器上使用php5.5.现在,我想使用pthreads.这是我的php配置: http://dd19010.kasserver.com/infophp.php55
I use php5.5 on my webserver. Now I want to use pthreads. Here's my php config: http://dd19010.kasserver.com/infophp.php55
实现此代码后.....
After implementing this code.....
<?php
class AsyncOperation extends Thread
{
public function __construct($threadId)
{
$this->threadId = $threadId;
}
public function run()
{
printf("T %s: Sleeping 3sec\n", $this->threadId);
sleep(3);
printf("T %s: Hello World\n", $this->threadId);
}
}
$start = microtime(true);
for ($i = 1; $i <= 5; $i++) {
$t[$i] = new AsyncOperation($i);
$t[$i]->start();
}
echo microtime(true) - $start . "\n";
echo "end\n";
?>
...问题是这个错误:致命错误:在中找不到类'Thread'. 我是否必须包含一些 include_once 或类似的东西才能使其正常工作? 我该怎么办?
... the problem is this very error: Fatal error: Class 'Thread' not found in. Do I have to include some include_once or something similar to make it work? What do I have to do??
我遇到了这个问题并设法解决了这个问题.
Hi I encountered this problem and managed to solve it.
首先,请考虑PHP的VC版本和扩展名的VC版本.在我的系统中,我从 http://windows.php附加了扩展名为pthreads.dll
的VC14版本.net/downloads/pecl/releases/pthreads/,但我的PHP VC版本是VC11.寻找与PHP的VC版本匹配的较低版本.
First, consider the VC version of your PHP and the VC version of extension. In mine I attached the extension pthreads.dll
with version VC14 from http://windows.php.net/downloads/pecl/releases/pthreads/ but my PHP VC version is VC11. Look for the lower version to match with the VC version of your PHP.
第二,也许您错过了PHP页面上的第3步.它指出您需要将pthreadVC2.dll
复制到其他文件夹.这是完整的说明.
Second, maybe you missed the step #3 at PHP page. It states that you need to copy the pthreadVC2.dll
to different folder. Here's the full instruction.
-
使用phpinfo()找出什么是"PHP Extension Build"版本.您可以使用此- http://localhost/?phpinfo = 1
下载与您的php版本(32位或64位)和php扩展版本(当前使用的VC11)相匹配的pthread.使用此链接下载- http://windows.php.net/downloads/pecl/版本/pthreads/
Download the pthreads that matches your php version (32 bit or 64 bit) and php extension build (currently used VC11). Use this link for download - http://windows.php.net/downloads/pecl/releases/pthreads/
解压缩- 将php_pthreads.dll移至"bin \ php \ ext \"目录. 将pthreadVC2.dll移至"bin \ php \"目录. 将pthreadVC2.dll移至"bin \ apache \ bin"目录. 将pthreadVC2.dll移至"C:\ windows \ system32"目录.
Extract the zip - Move php_pthreads.dll to the 'bin\php\ext\' directory. Move pthreadVC2.dll to the 'bin\php\' directory. Move pthreadVC2.dll to the 'bin\apache\bin' directory. Move pthreadVC2.dll to the 'C:\windows\system32' directory.
打开php \ php.ini并添加 extension = php_pthreads.dll
Open php\php.ini and add extension=php_pthreads.dll
参考: https://secure.php.net/manual/zh/pthreads.installation.php