pthread not working in php

installation, multithreading, php

Solution

There are two issues here:

1) First have to look for dll files location correctly. dll files should be placed as below:

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

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

extension=php_pthreads.dll

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.

Problem

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

Original source