True PHP7 Multi-Threading: How to Rebuild PHP and use pthreads

Building PHP on Mac and Linux with Multi-Threading and pthreads examples

phpbrew Introduction

Why use phpbrew over a vanilla build command?

phpbrew ext install github:krakjoe/pthreads

Using phpbrew on Mac OS

curl -L -O https://github.com/phpbrew/phpbrew/raw/master/phpbrew
chmod +x phpbrew
sudo mv phpbrew /usr/local/bin/phpbrew
phpbrew init
[[ -e ~/.phpbrew/bashrc ]] && source ~/.phpbrew/bashrc
phpbrew known
phpbrew update

Mac: Installing PHP dependencies

port install curl automake autoconf icu depof:php72 depof:php72-gd mcrypt bison re2c gettext openssl

Mac: Building PHP

phpbrew install php-7.2.12 +default -- --enable-maintainer-zts

Mac: Using the New Build

phpbrew use php-7.2.12

Mac: Installing pthreads

phpbrew ext install github:krakjoe/pthreads
phpbrew ext install mongodb
phpbrew ext install xdebug stable
phpbrew app get composer

Using phpbrew on Cent OS7

sudo yum install make automake gcc gcc-c++ kernel-develsudo yum install php php-devel php-pear bzip2-devel yum-utils bison re2c libmcrypt-devel libpqxx-devel libxslt-devel pcre-devel libcurl-devel libgsasl-devel openldap-devel, httpd-devel
yum install readline-devel
sudo yum -y install epel-release
wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7*.rpm
cd /etc/yum.repos.d/#open php7.2 repo file and change enabled=0 to enabled=1
sudo vi remi-php72.repo
sudo yum install php php-gd php-common php-mysql php-mcrypt php-devel php-xml

CentOS: Installing phpbrew

curl -L -O https://github.com/phpbrew/phpbrew/raw/master/phpbrew
chmod +x phpbrew
sudo mv phpbrew /usr/local/bin/phpbrew
phpbrew init
[[ -e ~/.phpbrew/bashrc ]] && source ~/.phpbrew/bashrc
phpbrew known
phpbrew update

CentOS: Building PHP

phpbrew install php-7.2.12 +default +openssl=/usr -- --enable-maintainer-zts --with-libdir=lib64

CentOS: Using the New Build

phpbrew use php-7.2.12

CentOS: Installing pthreads

phpbrew ext install github:krakjoe/pthreads
phpbrew ext install mongodb
phpbrew ext install xdebug stable
phpbrew app get composer

Using pthreads

class MyProgram extends Thread {   public function run() {      //run my program      echo "Woo, I am running in a new thread!";
}
}
$program1 = new MyProgram;$program1->start() && $program1->join();echo 'Thread finished';

Example 1: Successively Joining Threads

Example 2: Running Threads Simultaneously

Can Threads be used in namespace classes?

Exploring pthreads

To Conclude

Programmer and Author. Director @ JKRBInvestments.com. Creator of LearnChineseGrammar.com for iOS and Android.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store