Skip to content

Instantly share code, notes, and snippets.

@Sanix-Darker
Created June 28, 2025 21:47
Show Gist options
  • Save Sanix-Darker/f28e7f2d3f77dadaf676de49c4c65855 to your computer and use it in GitHub Desktop.
Save Sanix-Darker/f28e7f2d3f77dadaf676de49c4c65855 to your computer and use it in GitHub Desktop.
PHP 8.3 with ZTS (Zend Thread Safety) and pthreads

PHP 8.3 with ZTS (Zend Thread Safety) and pthreads

Here's an updated guide for compiling PHP 8.3 with ZTS support, which is required for pthreads or parallel extensions:

Prerequisites

sudo apt-get update
sudo apt-get install -y build-essential autoconf bison re2c \
    libxml2-dev libsqlite3-dev libssl-dev zlib1g-dev \
    libcurl4-openssl-dev libonig-dev libreadline-dev \
    libzip-dev pkg-config git

Download PHP 8.3 Source

wget https://www.php.net/distributions/php-8.3.0.tar.gz
tar -xzvf php-8.3.0.tar.gz
cd php-8.3.0

Configure with ZTS

./buildconf --force
./configure \
    --prefix=/usr/local/php8.3-zts \
    --enable-zts \
    --enable-mbstring \
    --enable-intl \
    --enable-pcntl \
    --enable-phpdbg \
    --enable-opcache \
    --with-openssl \
    --with-pear \
    --with-readline \
    --with-zlib \
    --with-curl \
    --enable-cli

Compile and Install

make -j$(nproc)
sudo make install

Verify ZTS Installation

/usr/local/php8.3-zts/bin/php -i | grep "Thread Safety"

This should output: Thread Safety => enabled

Install pthreads or parallel extension

For modern PHP threading, you'll want the parallel extension:

git clone https://github.com/krakjoe/parallel.git
cd parallel
/usr/local/php8.3-zts/bin/phpize
./configure --with-php-config=/usr/local/php8.3-zts/bin/php-config
make
sudo make install

Add the extension to your php.ini:

extension=parallel.so

Notes

  1. PHP 8.3's ZTS implementation has improved thread safety features compared to older versions.
  2. The parallel extension is the modern alternative to pthreads for PHP 8.x.
  3. Remember that not all PHP extensions are thread-safe, even with ZTS enabled.
  4. For production use, consider additional configuration options based on your needs.

To use this PHP installation as your default, add it to your PATH:

export PATH="/usr/local/php8.3-zts/bin:$PATH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment