Skip to content

Instantly share code, notes, and snippets.

@vpnwall-services
Created October 5, 2018 16:04
Show Gist options
  • Save vpnwall-services/27fab8cb1e5d3aec6df23495226c637e to your computer and use it in GitHub Desktop.
Save vpnwall-services/27fab8cb1e5d3aec6df23495226c637e to your computer and use it in GitHub Desktop.
[Install PHP pthreads] Install PHP pthreads #linux #script #bash #php #install #pthreads #zts #compile
#!/bin/bash
apt-get update && \
apt-get install -y 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 \
checkinstall
cd $HOME
wget https://github.com/php/php-src/archive/php-7.2.5.tar.gz
tar --extract --gzip --file php-7.2.5.tar.gz
cd $HOME/php-src-php-7.2.5
./buildconf --force
CONFIGURE_STRING="--prefix=/etc/php7 --with-bz2 --with-zlib --enable-zip --disable-cgi \
--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-maintainer-zts \
--with-tsrm-pthreads --enable-debug --enable-fpm \
--with-fpm-user=www-data --with-fpm-group=www-data"
./configure $CONFIGURE_STRING
make
checkinstall
dpkg -i php-src-php_7.2.5-1_amd64.deb
chmod o+x /etc/php7/bin/phpize
chmod o+x /etc/php7/bin/php-config
git clone https://github.com/krakjoe/pthreads.git
cd pthreads
/etc/php7/bin/phpize
./configure \
--prefix='/etc/php7' \
--with-libdir='/lib/x86_64-linux-gnu' \
--enable-pthreads=shared \
--with-php-config='/etc/php7/bin/php-config'
make && make install
cd $HOME/php-src-php-7.2.5
sudo mkdir -p /etc/php7/cli/
sudo cp php.ini-production /etc/php7/cli/php.ini
echo "extension=pthreads.so" | sudo tee -a /etc/php7/cli/php.ini
echo "zend_extension=opcache.so" | sudo tee -a /etc/php7/cli/php.ini
mv /usr/bin/php /usr/bin/php.original
ln -s /etc/php7/bin/php /usr/bin/php
php -v
cat << EOF > /tmp/pthreads-tester.php
<?php
class Task extends Threaded
{
private $value;
public function __construct(int $i)
{
$this->value = $i;
}
public function run()
{
$s=0;
for ($i=0; $i<10000; $i++)
{
$s++;
}
echo "Task: {$this->value}\n";
}
}
# Create a pool of 4 threads
$pool = new Pool(4);
for ($i = 0; $i < 15000; ++$i)
{
$pool->submit(new Task($i));
}
while ($pool->collect());
$pool->shutdown();
EOF
php /tmp/pthreads-tester.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment