Remember: Windows users can download binary packages from pecl.

Building on Anything Good: Linux/Mac

pthreads can be built as a shared library or statically compiled into PHP. Your PHP build must have ZTS enabled. If you do not have ZTS enabled on your build you will need to build a copy for yourself.

It’s not as scary as it sounds – in general PHP has a lot of libraries loaded that your site will never use and you can and should take this opportunity to tailor your installation. If you have done this already and still have your build tree around most modern servers will have you up and running in a few minutes.

Choosing a PHP Version

pthreads will compile and work with any version of PHP5 from 5.3.0 onwards.

Things to Do:

  1. Save your current PHP configuration – php.ini, and configure command from build time
  2. Download the PHP sources and unpack them
  3. Download the pthreads sources and unpack them to in the root of the PHP source to ext/pthreads
  4. Rebuild the configure script that PHP ships with so it includes the pthreads configuration at configure and build time
  5. Configure PHP with –enable-maintainer-zts –enable-pthreads
  6. Build and Install PHP

Show Me

I cannot show commands that can be used verbatim, because this is a custom process that must be tailored to your development environment, as I’m sure you know, I can however provide detailed information and recommendations ( see above ) and a pseudo shell session:

cat /etc/php.ini > /usr/src/php.factory.ini
php -i | grep configure > /usr/src/php.factory.config 
cd /usr/src
tar -xf php-5.3.17.tar.bz2
cd php-5.3.17/ext
wget -O pthreads.tar.gz
tar -xf pthreads.tar.gz
mv krakjoe-pthreads* pthreads
cd ../
./buildconf --force
./configure --enable-maintainer-zts --enable-pthreads --prefix=/usr
make install

If you took my advice and saved your configure line you can copy your configuration if by some miracle the default is perfect for you 🙂 While php is configuring if it complains about something missing consult the original configure line, try an apt-get|yum install PACKAGE-devel to resolve the complaint, often libraries are in separate packages to header files so while you might have other programs on the system that use libxml, and have libxml2 shared library, those packages were built on machines with the headers installed but not packaged by default as they are not required at runtime.

Additional configure options that you will find useful are –with-config-file-path and –with-config-file-scan-dir

./configure --enable-maintainer-zts --enable-pthreads --with-config-file-scan-dir=/etc/php.d --with-config-file-path=/etc --prefix=/usr

To build an isolated instance of PHP, you should –prefix with a custom path like:

./configure --enable-maintainer-zts --enable-pthreads --with-config-file-scan-dir=/etc/php.d --with-config-file-path=/etc --prefix=/home/username/debug-php

Before you “make install”, from the root of the build tree, you might think about running the few tests that are provided with pthreads to ensure basic functionality will work ( and please please please report anything that doesn’t )

TEST_PHP_EXECUTABLE=sapi/cli/php sapi/cli/php run-tests.php ext/pthreads

Building on Windows

This is an exhaustive subject, and I will assume that if you want to build on Windows you don’t require help, suffice to say that pthreads builds on Windows and requires pthreadVC2.lib from pthread-w32.

Pre-built binaries are available on pecl for Windows Users ( x86 VC9 ) for both PHP5.3 and PHP5.4 releases.