Skip to content

Instantly share code, notes, and snippets.

@simonrcodrington
Last active October 9, 2018 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonrcodrington/2bedd61d1216991b33b169903738fad6 to your computer and use it in GitHub Desktop.
Save simonrcodrington/2bedd61d1216991b33b169903738fad6 to your computer and use it in GitHub Desktop.
Getting pthreads working with WAMP CLI on Windows

Getting pthreads working with WAMP CLI

A quick guide on how to get pthreads (parallel threads) working with your local WAMP environment under PHP 7.1~

Issues

Current versions of pthreads wont work with PHP 7.0/7.1, because of issues they've locked use of pthreads to PHP 7.2+ (because of some security issues)

Latest versions of pthreads (3.1.6) wont work with PHP. However, version 3.1.7 beta will work with PHP 7.1/7.2.

To get pthreads working on windows (for WAMP), you will need to download the PECL file (version 3.1.7 from here: https://github.com/SirSnyder/pthreads/releases/tag/v3.1.7-beta.1)

Warning

Pthreads V2 (used for PHP5) had a warning saying it shouldn't be used in a web server environment. Version 3 (for PHP7+) now has an error. The dev has decided that it will not work with web servers and will not load, even if you try.

Pthreads is to be used on CLI only. If you try and load it via WAMP (Wamp > php extensions > pthreads) WAMP will trigger a fatal error on PHP compile.

Process

Copy dll files into locations

After downloading the above file, you'll find the folowing files

  • pthreadsVC2.dll
  • php_pthreads.dll

These need to be added to your WAMP directory so that you can use pthreads

Copy pthreadsVC2.dll into

C:\wamp64\bin\php\php7.1.9 C:\wamp64\bin\apache\apache2.4.27\bin

Copy php_pthreads.dll into

C:\wamp64\bin\php\php7.1.9\ext

Update php.ini files

We need to update the .ini files so that PHP knows to use the extension.

Update the PHP php-cli.ini file

C:\wamp64\bin\php\php7.1.9\

Dont edit the php.ini file in your PHP folder in WAMP, that file is used for the web server. You need to edit the php-cli-.ini in the same directory (if you don't have one that's fine, copy the standard .ini file and rename it).

Edit the ini file and scroll to the bottom. Add in the following to enable the extension

extension=php_pthreads.dll

Restart all WAMP services

Restart WAMP and ensure that it turns green (meaning it was successful). If it doesn't turn green look in the PHP error log (as that can indicate if it couldn't be found or something happened)

Verify pthreads loaded in CLI

Open up your terminal editor (for example git bash)

  • php -v - See the version of PHP on the command line (ensure it's the same version you've been adjusting)
  • php -i - Get the full phpinfo() breakdown (to see where the config file is loaded from)
  • php -m - See all of the modules loaded. You should see pthreads

Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment