4

I'm trying to have threads in my php code, but I can't get my head around pthreads library and every time I run my program I encounter this error:

Warning: PHP Startup: Unable to load dynamic library 'C:\php\ext\php_pthreads.dll' - The specified module could not be found.in Unknown on line 0

I followed every step needed:

I've added the file pthreadVC2.dll in my "C:\php" folder
I've added the file php_pthreads.dll in my "C:\php\ext"folder
I've modified the file php.ini, enabling the extension: extension=php_pthreads.dll
I've also added pthreadVC2.dll to system32 folder.

Here is my phpinfo():

PHP Version => 5.6.38
Compiler => MSVC11 (Visual C++ 2012)
Architecture => x64

And here is the version of pthreads I used:

php_pthreads-2.0.9-5.6-ts-vc11-x64

I have read similar topics on the issue, even did try everything step by step according to a video tutorial but nothing works. What am I doing wrong?

HessamSH
  • 357
  • 1
  • 5
  • 18
  • 1
    I'm not familiar with the extension but the manual is packed with warnings about not being usable in web server environment and requiring ZTS (Zend Thread Safety) enabled. Are you using a command-line build compiled with `--enable-zts`? – Álvaro González Sep 30 '18 at 10:07
  • I'm working on Windows. – HessamSH Oct 01 '18 at 05:42

1 Answers1

4

Installation is quite straightforward, although a little more involved than the Simple Windows Installation instructions suggest:

  1. Download a thread safe version of PHP, e.g. php-5.6.38-Win32-VC11-x86.
    • extract the .ZIP file to your hard drive, e.g. C:\php.
  2. Download the matching version of pthreads, e.g php_pthreads-2.0.10-5.6-ts-vc11-x86.
    • extract pthreadVC2.dll into the PHP folder, e.g. C:\php.
    • extract php_pthreads.dll into the extensions folder, e.g. C:\php\ext.
  3. In the PHP folder, copy either php.ini-development or php.ini-production to php.ini.
  4. Edit php.ini and add the line extension=php_pthreads.dll at the end of the file.

At this point pthreads should be working. You can verify this by opening a command prompt in the PHP folder and executing php --ri pthreads:

Screenshot of result

Note that the PHP and pthreads versions I referenced above require you to install the Visual Studio 2012 (VC11) runtime to function.


Edit: For completeness, I downloaded what seem to be the exact versions of PHP and pthreads you are using (the primary difference being x64):

Following the steps above I received the same result (except the pthreads version is reported as 2.0.9 of course).

timclutton
  • 12,682
  • 3
  • 33
  • 43
  • Does the Zend Thread Safety requirement mentioned in the manual still apply? – Álvaro González Oct 02 '18 at 06:43
  • @ÁlvaroGonzález Yes, according to the [requirements on the GitHub page](https://github.com/krakjoe/pthreads#requirements) and the [PHP manual itself](http://php.net/manual/en/pthreads.requirements.php). (I did write 'a thread safe version of PHP' in point 1.) – timclutton Oct 02 '18 at 07:56
  • Hmmm... I think the confusing part is the reference to the `--enable-zts` build switch. I was expecting to see it in `phpinfo()` ("Configure Command" section). Is then the information under "Thread Safety" the same as "Zend Thread Safety" (in other words, is there a "Zend" kind of thread safety or it's all the same?) – Álvaro González Oct 02 '18 at 09:06
  • In my ignorance I've always assumed that ZTS and TS are one and the same. Since pthreads works, as outlined in my answer, the evidence seems to support that. I typically work on Windows and use the pre-built versions of PHP from php.net. Perhaps it's possible to compile with only one of ZTS or TS if you do it yourself? – timclutton Oct 02 '18 at 09:10
  • 1
    If it works for you with the official binaries then it's clear that my assumption about "Configure Command" was wrong. Nice and thorough answer! – Álvaro González Oct 02 '18 at 09:30