PHP/pthreads extension

From ArchWiki
< PHP
(Redirected from PHP pthreads extension)

If you wish to have POSIX multi-threading you will need the pthreads extension (or the parallel extension for PHP 7.4+). To install the pthreads or parallel extension using pecl you are required to use a compiled version of PHP with the thread safety support flag --enable-maintainer-zts. Currently, the most clean way to do this would be to rebuild the original package with the proper flag.

Check what packages depend on the php package, for example:

$ pacman -Qii php
:: php-apache: requires php
:: php-apcu: requires php
:: php-pear: requires php

Uninstall all those including php.

Use the ABS to acquire the build files for each of them, modify the PKGBUILD in their folder to add --enable-maintainer-zts, next to the other extensions. It should look like:

...
--with-xsl=shared \
--with-zip=shared \
--with-zlib \
--enable-maintainer-zts
...

Make the new packages with makepkg, then install the rebuild version of the packages you had previously removed:

# pacman -U \
php-version-release-x86_64.pkg.tar.zstd \
php-apache-version-release-x86_64.pkg.tar.zstd \
php-pear-version-release-x86_64.pkg.tar.zstd \

On some versions of PHP, php-pearAUR is missing and it is needed to run pecl. As adding --with-pear in the file above does not solve it, you will need to install it separately.

Then install pthreads:

$ pecl install pthreads

or install parallel for recent PHP versions:

$ pecl install parallel

If you installed parallel, you will need to edit /etc/php/php.ini and add the parallel extension, it should look like:

...
;extension=odbc
;zend_extension=opcache
extension=parallel
;extension=pdo_dblib
...

Install the php-apcu package for APC support back.