PHP pthreads: Fatal error: Class 'Thread' not found

匿名 (未验证) 提交于 2019-12-03 01:14:02

问题:

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.....

 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 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_once or something similar to make it work? What do I have to do??

回答1:

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.

You may need to copy the pthreadsVC2.dll into the bin directory of your web service as well.

/etc/php55/fpm/ 

You're looking for the folder with php.ini in it.

Make sure the php.ini file has the line added:

extension=php_pthreads.dll 


回答2:

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.

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.

  1. Find out what is your 'PHP Extension Build' version by using phpinfo(). You can use this - http://localhost/?phpinfo=1

  2. 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/

  3. 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.

  4. Open php\php.ini and add extension=php_pthreads.dll

Reference: https://secure.php.net/manual/en/pthreads.installation.php



回答3:

I am using WAMP and found that the pthreadVC2.dll should go to the Apache folder instead:

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.dll should still go to:

C:\wamp\bin\php\php5.5.12\ext

After this, search in this file:

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).

Exit WAMP and start it again. You should now see in WAMP menu under PHP > PHP extensions, the new php_pthreads extension.



回答4:

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.



回答5:

By default Threads are not implemented in PHP, and according to your phpinfo it does not seem to be loaded. Check out the PHP manual on how to set-up/configure the module.



回答6:

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!