PHP pthreads:致命错误:找不到“线程”类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22901578/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP pthreads: Fatal error: Class 'Thread' not found
提问by ItsMeDom
I use php5.5 on my webserver. Now I want to use pthreads. Here's my php config: http://dd19010.kasserver.com/infophp.php55
我在我的网络服务器上使用 php5.5。现在我想使用 pthreads。这是我的 php 配置: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";
?>
... the problem is this very error: Fatal error: Class 'Thread' not found in. Do I have to include some include_onceor something similar to make it work? What do I have to do??
...问题就是这个错误:致命错误:在. 我是否必须包含一些include_once或类似的东西才能使其工作?我需要做什么??
回答by Player1
Hi I encountered this problem and managed to solve it.
嗨,我遇到了这个问题并设法解决了它。
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 的 VC 版本和扩展的 VC 版本。在我的中,我pthreads.dll
从http://windows.php.net/downloads/pecl/releases/pthreads/附加了VC14 版本的扩展,但我的 PHP VC 版本是 VC11。寻找与您的 PHP 的 VC 版本匹配的较低版本。
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.
其次,也许您错过了 PHP 页面的第 3 步。它指出您需要将其复制pthreadVC2.dll
到不同的文件夹。这是完整的说明。
Find out what is your 'PHP Extension Build' version by using phpinfo(). You can use this - http://localhost/?phpinfo=1
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/
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.
Open php\php.ini and add extension=php_pthreads.dll
使用 phpinfo() 找出您的“PHP 扩展构建”版本是什么。你可以使用这个 - http://localhost/?phpinfo=1
下载与您的 php 版本(32 位或 64 位)和 php 扩展构建(当前使用的 VC11)匹配的 pthread。使用此链接下载 - http://windows.php.net/downloads/pecl/releases/pthreads/
解压缩 zip - 将 php_pthreads.dll 移动到“bin\php\ext\”目录。将 pthreadVC2.dll 移动到“bin\php\”目录。将 pthreadVC2.dll 移动到“bin\apache\bin”目录。将 pthreadVC2.dll 移动到“C:\windows\system32”目录。
打开 php\php.ini 并添加 extension=php_pthreads.dll
Reference: https://secure.php.net/manual/en/pthreads.installation.php
参考:https: //secure.php.net/manual/en/pthreads.installation.php
回答by Murat ?akmak
1) Create one php file
phpinfo(); --> Run
Example: Info
PHP Version: 5.6.31
Compiler: MSVC11 (Visual C++ 2012)
Architecture: x64
2)Go to website:
http://windows.php.net/downloads/pecl/releases/pthreads/
Example 2.0.9 file
Compiler:VC11
Architecture:x64
php_pthreads-2.0.9-5.6-ts-vc11-x64.zip download.
3)Extract php_pthreads.dll and pthreadVC2.dll.
wamp\bin\php\php5.6.31\ext\ --> copy php_pthreads.dll
wamp\bin\php\php5.6.31\ --> copy pthreadVC2.dll
wamp\bin\apache\apache2.4.27\bin --> copy pthreadVC2.dll
4)Now edit php.ini
wamp\bin\apache\apache2.4.27\bin\php.ini\ --> Add extension=php_pthreads.dll
wamp\bin\php\php5.6.31\php.ini\ --> Add extension=php_pthreads.dll
5)Now Restart Wamp
1)创建一个php文件
phpinfo();--> 运行
示例:Info
PHP 版本:5.6.31
编译器:MSVC11 (Visual C++ 2012)
架构:x64
2) 访问网站:
http : //windows.php.net/downloads/pecl/releases/pthreads/
Example 2.0 .9 文件
编译器:VC11
架构:x64
php_pthreads-2.0.9- 5.6-ts- vc11- x64.zip 下载。
3)解压php_pthreads.dll和pthreadVC2.dll。
wamp\bin\php\php 5.6.31\ext\ -->复制 php_pthreads.dll
wamp\bin\php\php 5.6.31\ -->复制 pthreadVC2.dll
wamp\bin\apache\apache2.4.27\bin - ->复制 pthreadVC2.dll
4)现在编辑 php.ini
wamp\bin\apache\apache2.4.27\bin\ php.ini\ -->添加 extension=php_pthreads.dll
wamp\bin\php\php 5.6.31\ php.ini\ -->添加 extension=php_pthreads.dll
5) 现在重启 Wamp
回答by Kyohei Kaneko
Your phpinfo shows that you have php with thread safety disabled. You need to install a version of php that is thread safe to use pthreads. This may or may not fix your current issue though.
您的 phpinfo 显示您已禁用线程安全的 php。您需要安装一个线程安全的 php 版本才能使用 pthreads。不过,这可能会也可能不会解决您当前的问题。
You may need to copy the pthreadsVC2.dll
into the bin directory of your web service as well.
您可能还需要将 复制pthreadsVC2.dll
到您的 Web 服务的 bin 目录中。
/etc/php55/fpm/
You're looking for the folder with php.ini in it.
您正在寻找包含 php.ini 的文件夹。
Make sure the php.ini file has the line added:
确保 php.ini 文件添加了以下行:
extension=php_pthreads.dll
回答by Armfoot
I am using WAMP and found that the pthreadVC2.dllshould go to the Apache folder instead:
我正在使用 WAMP,发现pthreadVC2.dll应该转到 Apache 文件夹:
C:\wamp\bin\apache\apache2.4.9\bin
C:\wamp\bin\apache\apache2.4.9\bin
Unlike what is written in README.md, you don't need to have it in the PHP folder, but the php_pthreads.dllshould still go to:
与README.md中所写的不同,您不需要将它放在 PHP 文件夹中,但php_pthreads.dll仍应转到:
C:\wamp\bin\php\php5.5.12\ext
C:\wamp\bin\php\php5.5.12\ext
After this, search in this file:
在此之后,在此文件中搜索:
C:\wamp\bin\apache\apache2.4.9\bin\php.ini
C:\wamp\bin\apache\apache2.4.9\bin\php.ini
For ;extension=php_pgsql.dll
and add extension=php_pthreads.dll
in a new line after it (yes, it's the bin\php.ini in the Apache folder, not the one in the PHP folder).
对于;extension=php_pgsql.dll
添加extension=php_pthreads.dll
后,在新线(是的,它是在Apache的文件夹中bin \ php.ini中,没有一个在PHP文件夹)。
Exit WAMP and start it again. You should now see in WAMP menu under PHP > PHP extensions, the new php_pthreadsextension.
退出 WAMP 并重新启动它。您现在应该在 WAMP 菜单下的PHP > PHP extensions中看到新的php_pthreads扩展。
回答by Hristo Petev
I think you need to include the extensions int he php.ini file, because I can't see it in the config. You can see that each library has its own section like MySQL, but there isn't such for the threads. I haven't used threads ever but that should be a good place to start from.
我认为您需要在 php.ini 文件中包含扩展名,因为我在配置中看不到它。你可以看到每个库都有自己的部分,比如 MySQL,但线程没有这样的部分。我从未使用过线程,但这应该是一个很好的起点。
回答by Paul
By default Threads are not implemented in PHP, and according to your phpinfo it does not seem to be loaded. Check out the PHP manualon how to set-up/configure the module.
默认情况下,线程未在 PHP 中实现,根据您的 phpinfo,它似乎没有被加载。查看有关如何设置/配置模块的PHP 手册。