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:
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
There are two issues here:
1) First have to look for dll files location correctly. dll files should be placed as below:
and in php.ini file only php_pthreads.dll should be enabled as
2) Have to look for Versions of PHP and dll file.
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".
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.
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.
If you have installed PHP on a different folder rather than C:/PHP5, it is good to add pthreadVC2.dll to httpd.conf. Otherwise, pthreads extension module can not find it.
NOTE: If after adding LoadFile, still Apache can not find DLL, just remove the Loadfile line and copy the DLL to Apache bin folder.
I found a solution that worked for me:
You should first verify you've downloaded the right package for your specific system (php version, 64/32 bit system).
After that, you should include the relevant files in multiple places. It's really important to put them in every place described since otherwise it just won't work.
You should also change your php.ini file as described above (only for the php_pthreads.dll).
I've been using this with WAMP on a Windows 7 64 bit system.