DEV Community

Cover image for PHP multi threads - Setup PHP7.2 cli with pthreads
Peham Raza
Peham Raza

Posted on

PHP multi threads - Setup PHP7.2 cli with pthreads

PHP multi threads - Setup PHP 7.2cli with Multiple Threads (pthreads) on Ubuntu

In this article I'm going to write steps required to setup PHP multi threads on your server.

*Why PHP multi threads - CLI Version: *

Running app on PHP 5.6 for web app but need PHP7.2 (pthreads) with multiple threads to run tasks at background so we can run multiple independent business logics without interfering with main web app.



Install required libraries

sudo apt-get install libc-client-dev libkrb5-dev libgmp-dev apache2-dev libzip-dev bison autoconf build-essential pkg-config git-core libltdl-dev libbz2-dev libxml2-dev libxslt1-dev libssl-dev libicu-dev libpspell-dev libenchant-dev libmcrypt-dev libpng-dev libjpeg8-dev libfreetype6-dev libmysqlclient-dev libreadline-dev libcurl4-openssl-dev
sudo ln -s /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h
Enter fullscreen mode Exit fullscreen mode



Download & Build PHP

wget https://github.com/php/php-src/archive/php-7.2.19.tar.gz
tar --extract --gzip --file php-7.2.19.tar.gz
cd php-src-php-7.2.19
./buildconf --force
Enter fullscreen mode Exit fullscreen mode



CONFIGURE_STRING="--prefix=/etc/php7 --with-bz2 --with-zlib --enable-zip --disable-cgi \
--with-apxs2=/usr/bin/apxs2 --with-gmp --with-imap \ 
--enable-soap --enable-intl --with-openssl --with-readline --with-curl --enable-ftp \
--enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-sockets \
--enable-pcntl --with-pspell --with-enchant --with-gettext --with-gd --enable-exif \
--with-jpeg-dir --with-png-dir --with-freetype-dir --with-xsl --enable-bcmath \
--enable-mbstring --enable-calendar --enable-simplexml --enable-json --enable-hash \
--enable-session --enable-xml --enable-wddx --enable-opcache --with-pcre-regex \
--with-config-file-path=/etc/php7/cli --with-config-file-scan-dir=/etc/php7/etc \
--enable-cli --enable-debug --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data \
--with-mcrypt --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-shmop \
--enable-pthreads --with-tsrm-pthreads --enable-maintainer-zts"
Enter fullscreen mode Exit fullscreen mode



./configure $CONFIGURE_STRING
Enter fullscreen mode Exit fullscreen mode
make && sudo make install
Enter fullscreen mode Exit fullscreen mode



Check it's installed (this should print 1)

/etc/php7/bin/php -r "echo PHP_ZTS;"
Enter fullscreen mode Exit fullscreen mode

Read remaining steps on peham.dev

Top comments (0)