Skip to content

Instantly share code, notes, and snippets.

@igorgolovanov
Forked from krakjoe/pthreads-helper
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igorgolovanov/d1b34ebd44de9c708220 to your computer and use it in GitHub Desktop.
Save igorgolovanov/d1b34ebd44de9c708220 to your computer and use it in GitHub Desktop.
#!/bin/bash
# This should be a path that the user executing the script can read and write
PHP_PATH=/opt/php-ts
# This should be a sensible version of PHP
PHP_VERSION=5.4.11
# This should be a sensible mirror for your location
PHP_MIRROR=uk1.php.net
# This should be a released version of pthreads
PHP_PTHREADS=0.0.42
# This should be set to 0 if you do not want to remove build directories
PHP_CLEAN=1
# This should be adjusted when you have worked out how to replicate your setup
PHP_EXTRACONF=--disable-all
# This should be adjusted for the number of cores on your system
PHP_CORES=4
# This should be set to 0 should you need to see build output
PHP_SILENT=1
#########################################################
# STOP EDITING UNLESS YOU KNOW WHAT YOU ARE DOING
#########################################################
# Set root location
PHP_CONF_ROOT=$(realpath .)
# Clean previous build directory, if required
if [ $PHP_CLEAN -eq 1 ];
then
rm -rf $PHP_CONF_ROOT/php-$PHP_VERSION
rm -rf $PHP_CONF_ROOT/php-$PHP_VERSION.tar.bz2
rm -rf $PHP_CONF_ROOT/pthreads-$PHP_PTHREADS.tgz
fi
# Download PHP sources
echo "Downloading PHP $PHP_VERSION from $PHP_MIRROR ..."
wget -q http://www.php.net/get/php-$PHP_VERSION.tar.bz2/from/$PHP_MIRROR/mirror -O php-$PHP_VERSION.tar.bz2
if [ -f php-$PHP_VERSION.tar.bz2 ];
then
# Unpack PHP
tar -xf php-$PHP_VERSION.tar.bz2
if [ -d php-$PHP_VERSION ];
then
# Download pthreads
echo "Downloading pthreads $PHP_PTHREADS ..."
wget -q http://pecl.php.net/get/pthreads-$PHP_PTHREADS.tgz -O pthreads-$PHP_PTHREADS.tgz
if [ -f $PHP_CONF_ROOT/pthreads-$PHP_PTHREADS.tgz ];
then
# Unpack pthreads
echo "Unpacking pthreads $PHP_PTHREADS ..."
cd $PHP_CONF_ROOT/php-$PHP_VERSION/ext/
tar -xf $PHP_CONF_ROOT/pthreads-$PHP_PTHREADS.tgz
mv $PHP_CONF_ROOT/php-$PHP_VERSION/ext/pthreads-$PHP_PTHREADS $PHP_CONF_ROOT/php-$PHP_VERSION/ext/pthreads
# Reconfigure sources
/$PHP_CONF_ROOT/php-$PHP_VERSION/buildconf --force && \
/$PHP_CONF_ROOT/php-$PHP_VERSION/configure --prefix=$PHP_PATH \
--enable-maintainer-zts \
--with-config-file-path=$PHP_PATH \
--with-config-file-scan-dir=$PHP_PATH/modules.d \
--enable-pthreads $PHP_EXTRACONF
if [ $? -eq 0 ];
then
if [ $PHP_SILENT -eq 1 ];
then
echo "Building PHP $PHP_VERSION @ $PHP_PATH ..."
make -j$PHP_CORES -C $PHP_CONF_ROOT/php-$PHP_VERSION 2>&1 >/dev/null
else
make -j$PHP_CORES -C $PHP_CONF_ROOT/php-$PHP_VERSION
fi
if [ $? -eq 0 ];
then
echo "Installing PHP $PHP_VERSION ..."
make -C $PHP_CONF_ROOT/php-$PHP_VERSION install
if [ $? -eq 0 ];
then
echo "Success: PHP $PHP_VERSION installed with pthreads support @ $PHP_PATH/bin/php"
$PHP_PATH/bin/php -m
exit 0
fi
else
echo "Error: failed to build PHP"
exit 4
fi
else
echo "Error: failed to configure PHP"
exit 3
fi
else
echo "Error: failed to download pthreads sources"
exit 2
fi
else
echo "Error: failed to unpack PHP sources"
exit 1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment