Pthread does not work in php

I downloaded da Pthreads PHP file from http://windows.php.net/downloads/pecl/releases/pthreads/ and included it in php.ini as shown below:

extension=pthreadVC2.dll extension=php_pthreads.dll 

I used below code example:

 <?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:

Fatal error: class 'Thread' was not found in C: \ htdocs \ threads \ AsyncOperation.php on line 2 Call stack: 0,0008 333464 1. {main} () C: \ HTDOCS \ thread \ AsyncOperation.php: 0

+4
source share
3 answers

There are two problems here:

1) First you need to look for the location of the DLL files correctly. dll files should be placed as shown below:

 C:\PHP5\pthreadVC2.dll C:\PHP5\ext\php_pthreads.dll 

and in the php.ini file only php_pthreads.dll should be included as

 extension=php_pthreads.dll 

2) It is necessary to search for PHP Versions and DLL files.

My PHP is VC6 build and the dll file is VC9. This is why the module did not install. I recognized this difference using " php -m ".

Since there is no VC6 assembly in the DLL file, I used the PHP VC9 assembly and used pthreads, and the program works fine.

Note. The above two solutions solved my problems. But if you still get errors, check if xdebug or zend debuggers are enabled. Unplug them and try again.

+12
source

If you installed PHP in a different folder and not in C: / PHP5, it is useful to add pthreadVC2.dll to httpd.conf. Otherwise, the pthreads extension module cannot find it.

 LoadFile "c:/not_default_php5/pthreadVC2.dll" 

NOTE. If Apache still cannot find the DLL after adding the LoadFile, just delete the Loadfile line and copy the DLL to the Apache bin folder.

 c:/apache_home/bin/pthreadVC2.dll 
+4
source

I found a solution that worked for me:

First you need to check that you have downloaded the right package for your specific system (php version, 64/32-bit system).

After that, you should include the appropriate files in several places. It is very important to put them in every place, because otherwise it just won’t work.

You must also modify the php.ini file as described above (php_pthreads.dll only).

I used this with WAMP on a 64-bit Windows 7 system.

-1
source

All Articles