blawson7
blawson7

Reputation: 21

How to setup php for multithreading on redhat 6.5

I've coded in C++ and Java with multi-threading. I'd like to with PHP CLI, but haven't found a cut-and-dried method for setting the server up to allow multi-threading. I'd like to be able to use worker threads if possible, but need to set our server up. It is Redhat 6.5.

Thanks in advance.

Upvotes: 1

Views: 392

Answers (1)

Joe Watkins
Joe Watkins

Reputation: 17148

Prerequisites

To use pthreads, PHP must be built with thread safety enabled.

Note that, PHP does have a threading model, it is built with threaded architectures in mind.

However, it is not usually the default build mode for PHP, package maintainers tend to cater to the masses and the masses don't care about thread safety.

Configuration

If you have PHP installed currently and are using it with an apache prefork mpm or some other non-thread-safe setup, then leave that installation intact. The best thing to do is build an isolated installation of PHP for use at the console.

The following example session illustrates how you might isolate an installation in /opt

git clone https://github.com/php/php-src
cd php-src
git checkout PHP-5.6
./buildconf
./configure --prefix=/opt --with-config-file-path=/opt --with-config-file-scan-dir=/opt/etc.d --enable-maintainer-zts
make
sudo make install

Installing pthreads

With a thread safe build of PHP, installing pthreads is easy. The following example session illustrates how to install the latest pthreads sources

git clone https://github.com/krakjoe/pthreads
cd pthreads
phpize
./configure
make
sudo make install

Running the test suite distributed with pthreads is a good way to ensure everything is okay:

make test

To load pthreads all the time:

echo extension=pthreads.so > /opt/etc.d/pthreads.ini

Upvotes: 4

Related Questions