4

new php parallel. it's new and there is no troubleshooting about it anywhere and the only documentation about it, is php.net itself which is not enough.

this is what I did (per instructions):

  • installed latest version of WAMP(3.1.9 x64).
  • installed latest version of PHP(7.3.9) on WAMP.
  • added PHP to windows system environment path.
  • added pthreadVC2.dll to PHP folder & added pthreadVC2.dll to windows system environment path.
  • added php_parallel.dll to php/ext directory.
  • added extension=parallel to php.ini.
  • restarted everything.
<?php
# this is my code
$runtime = new \parallel\Runtime();

$future = $runtime->run(function(){
    for ($i = 0; $i < 50; $i++)
        echo "$i";
        
    return "easy";
});

for ($i = 0; $i < 50; $i++) {
    echo ".";
}

hours spent. now windows cmd says:
"Fatal error: Uncaught Error: Class 'parallel\Runtime' not found in ...[my file address]"
and wampserver says "The connection was reset (firefox error)" only on the page I use parallel\Runtime and the other pages work fine.
and please with all do respect don't mark my question as broad one or any other things if you simply don't know the answer. at least show me some links.

T.Todua
  • 53,146
  • 19
  • 236
  • 237
Miky1992
  • 133
  • 1
  • 5
  • I wonder why would you try to install it on windows because in production environment it won't be. Especially someyhing which manipulates thread or other system processes. Docker for windows now works fine and allow you to have a production like environment. If you have enough RAM tho. – job3dot5 Sep 05 '19 at 08:23
  • Have you ever figured it out? – T.Todua Apr 24 '21 at 08:50

4 Answers4

4

As far as I can tell, to install an extension from a .dll provided by PECL, the following need to match between your extension and your PHP build, found in phpinfo():

  1. PHP Version: Found in PHP Version
  2. Thread Safe: Found in PHP Extension Build (TS=threadsafe or NTS=not-threadsafe)
  3. Compiler Version: Found in PHP Extension Build (eg: VS15 or VS16)
  4. x86 vs x64: Found in Architecture

On the PECL repository for parallel, you should check latest updated version and the package names are self-explanatory, so you can choose your desired one, i.e. ... 7.3-ts-vc15-x64


Note (maybe does not apply now): Given the limited builds of parallel, your PHP Build must be: 7.3+, TS, and VC15. Double-check that this is indeed the case for you by looking at your phpinfo(), and also be sure you are using the x64 version (since you said your PHP is x64).

T.Todua
  • 53,146
  • 19
  • 236
  • 237
JS_Riddler
  • 1,443
  • 2
  • 22
  • 32
3

The correct answer is JS_Riddler's post (Dated Dec 3 '19 and edited by T.Todua), but I wanted to elaborate for Windows users.

Before you install, on the command line, if you do "php -v", you may see something like:

PHP 7.3.33 (cli) (built: Nov 16 2021 14:49:44) ( ZTS MSVC15 (Visual C++ 2017) x64 )

Don't let the "(Visual C++ 2017)" confuse you...it's the "ZTS MSVC15" that is important, indicating the thread-safe build and runtime library.

Also note the major and minor version numbers: "7.3" in the above example. The build number (eg the third number, '33' in the example) does not matter.

And also note the architecture: "x64" in the example.

The major version, minor version, and architecture need to match the version of parallel you download, so for the above example you would want to download

php_parallel-1.1.4-7.3-ts-vc15-x64.zip

Note: after downloading and unzipping the parallel archive:

  1. copy the php_parallel.dll file to php/ext/php_parallel.dll
  2. copy the pthreadsVC2.dll to php/pthreadsVC2.dll
  3. add "extension=parallel" somewhere in your php.ini on a line by itself.

you should be able to run "php -v" from a command line. If you get an error, double check that the php.exe (and pthreadsVC2.dll) are on your PATH and that the php_parallel.dll version you have in the php/ext folder matches the major and minor versions of your php executable.

Another note: Many hosting companies do not use the ZTS version of php, so it appears this extension is mostly for CLI development applications at this time. Don't try to write production code that relies on it unless you know your target host supports it.

samofvt
  • 41
  • 2
0

Error log turned out the saver.

PHP Startup: Failed to load .../php/php7.4.9/ext/pthreadVC2, The system cannot find the file ..

Then I've just removed .dll from file name, and then it gave:

PHP Startup: Invalid library (maybe not a PHP library) 'pthreadVC2' in Unknown on line 0

If I remember correctly, it turned out that WampServer (with it's builtin php) does not support multi-threading/safe-threading or like that, and it was not possible to use it on WampServer. However interesting thing turned out, is that it works in CLI.

T.Todua
  • 53,146
  • 19
  • 236
  • 237
0

I had the exact same issue. Also, I copied the file pthreadVC2.dll into the folder ext. When I moved this file out of the folder then it has worked fine.

Folders:

  • yourPhpFolder/pthreadVC2.dll
  • yourPhpFolder/ext/php_parallel.dll