0

I am trying to enable Thread with PHP script. I have followed the following steps for enabling PHP thread.

Step 1:- Download and unzip pthread lib from here

Step 2:- Copy php_pthreads.dll and paste into the php\php7.2.14\ext and php\php7.2.14\ folder.

Step 3:- and pthreadVC2.dll and paste into the apache\apache2.4.37\bin

Step 4:- Enable thread in php.ini which is located in apache\apache2.4.37\bin and after updating its look like something below.

; Whether or not to enable the dl() function.  The dl() function does NOT work
; properly in multithreaded servers, such as IIS or Zeus, and is automatically
; disabled on them.
; http://php.net/enable-dl
enable_extension=On
extension=php_pthreads.dll

Step 5:- Enable thread in php.ini in which located at \php\php7.2.14

; Whether or not to enable the dl() function.  The dl() function does NOT work
; properly in multithreaded servers, such as IIS or Zeus, and is automatically
; disabled on them.
; http://php.net/enable-dl
enable_dl = On
extension=php_pthreads.dll

Step 6:- I have restarted wampp server with all services.

Still, I am getting the error as

 Fatal error: Class 'Thread' not found in {PHP file with location with line number}.

Update

I have changed DLL files and restarted a server as we discussed and redirect to a new error as below.

[24-Jan-2019 10:29:20 UTC] PHP Fatal error:  The apache2handler SAPI is not supported by pthreads in Unknown on line 0
[24-Jan-2019 10:29:20 UTC] PHP Fatal error:  Unable to start pthreads module in Unknown on line 0
Dhiral Kaniya
  • 1,941
  • 1
  • 19
  • 32
  • It seems like you're using the extension for 7.0 and not 7.2. Check [this issue](https://github.com/krakjoe/pthreads/issues/792) on their Github for a link to a version that should work for 7.2 (it's still set as version 3.1.6, but has -7.2 instead of -7.0). – M. Eriksson Jan 24 '19 at 10:13
  • @Cid i have included #!/usr/bin/php in my script. – Dhiral Kaniya Jan 24 '19 at 10:20
  • My comment was stupid. Check @MagnusEriksson one, this will lead you to the right way – Cid Jan 24 '19 at 10:22
  • @Cid checking for his comment – Dhiral Kaniya Jan 24 '19 at 10:24
  • 2
    If you are using WAMPServer as you say, then `#!/usr/bin/php` will not be understood by Windows! – RiggsFolly Jan 24 '19 at 10:33
  • As @MagnusEriksson said it looks like you are using the wrong version of the extension. And there does not seem to be a version at least in that repo for PHP 7.2. So you will have to switch your PHP version down to a PHP7.0 version to be able to use `pthreads` – RiggsFolly Jan 24 '19 at 10:37
  • READ THE MANUAL [for pthreads](http://php.net/manual/en/intro.pthreads.php) It specifically states **Warning** _The pthreads extension cannot be used in a web server environment. Threading in PHP is therefore restricted to CLI-based applications only._ – RiggsFolly Jan 24 '19 at 10:38
  • @MagnusEriksson I have to change the dll file as suggested but apache does not allow to start my those scripts and I search about this error. This script can be run with PHP CLI only. is there any alternative to execute with apache server? – Dhiral Kaniya Jan 24 '19 at 10:39
  • @RiggsFolly so it means pthread does not support with php7.2. Am i right? – Dhiral Kaniya Jan 24 '19 at 10:40
  • Well the [github](https://github.com/krakjoe/pthreads) suggests it is supported (PHP CLI Only **not on web server**) but I have to assume that nobody has bothered to compile it for PHP7.1 or PHP7.2 as there does not seem to be a DLL compiled for any version of PHP after PHP7.0 – RiggsFolly Jan 24 '19 at 10:44
  • This bit if the file name `php_pthreads-3.1.6-**7.0**-ts-vc14-x86.zip` normally denoted the version of PHP that the code is compiled for – RiggsFolly Jan 24 '19 at 10:46
  • 1
    Please read the comments properly again. As stated, you were using the wrong version of the dll (and the github issue linked to a working one for PHP 7.2). Then it also states that it does not work on web servers, which includes Apache (which is a web server). So, even after upgrading the dll to the correct version, you still can't use it with Apache (or any other web server). It only works on PHP-scripts that are executed through the command line (like `cmd` etc). – M. Eriksson Jan 24 '19 at 10:53
  • @DhiralKaniya I suggest you to read [this question](https://stackoverflow.com/questions/9315714/what-is-difference-between-php-cli-and-php-cgi) – Cid Jan 24 '19 at 12:00
  • @all :- Finally I figure out the way and able to execute a script with pthread via cli. Learn a lot as i am new for PHP. thanks, each and everyone for important resources and guidance. – Dhiral Kaniya Jan 24 '19 at 16:39

0 Answers0