phppthreadsphp-8.1

PHP: pthreads not loading on PHP 8.1


I'm trying to add pthreads extension on PHP 8.1 TS and it doesn't seem to work, It's sayin that it is not installed while in fact it is.

PHP -v
PHP 8.1.10 (cli) (built: Aug 30 2022 18:05:49) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.1.10, Copyright (c) Zend Technologies
    with Xdebug v3.1.5, Copyright (c) 2002-2022, by Derick Rethans

Here are the steps I used to install it ->

  1. Get the latest release from here -> https://windows.php.net/downloads/pecl/releases/pthreads/
  2. Extract php_pthreads.dll to /php/ext
  3. Add extension=pthreads to php.ini
  4. Extract pthreadVC2 in to /php

And when I try to install Laravel Horizon this is what I get ->

Root composer.json requires PHP extension ext-pthreads * but it is missing from your system. Install or enable PHP's pthreads extension.

Solution

  • pthreads is not available for PHP 8.1

    PHP extensions need to be compiled against the correct version of PHP, because they interact directly with code that is only guaranteed stable within one annual release (e.g. 7.0.1 and 7.0.2 are guaranteed compatible, but 7.0.0 and 7.1.0 are not). They also generally require significant source code changes between major releases, i.e. an extension written for PHP 7.0 is reasonably likely to be compilable against PHP 7.4, but not against PHP 8.0.

    If you look at the downloads for an earlier version of pthreads, you'll see that the version of PHP is included in the filename - pthreads 2.0.10 has builds available for 5.3, 5.4, 5.5, and 5.6. The last release listed, 3.1.6, only has two files available, both built for PHP 7.0.

    Looking on Github, version 3.1.6 was tagged in Feb 2016, 10 months before PHP 7.1. There is a version 3.2.0 on Github, which mentions support for PHP 7.2, but this does not appear on the PECL page for the extension, which features a prominent banner:

    This package is not maintained anymore and has been superseded.

    Specifically, it was discontinued by the author in favour of a new extension called "parallel". That extension was updated for 8.0 and possibly 8.1; but due to health issues, Joe Watkins was unable to continue working on it. A new maintainer has now been given access, so releases for 8.2 and newer will hopefully follow.