Skip to content

Instantly share code, notes, and snippets.

@prisis
Last active September 8, 2020 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save prisis/4e81f5e52ad7e11518e4d2eb81d7e89d to your computer and use it in GitHub Desktop.
Save prisis/4e81f5e52ad7e11518e4d2eb81d7e89d to your computer and use it in GitHub Desktop.
tpecl is a helper to compile and cache php extensions on travis
#!/usr/bin/env bash
# How to use:
#
# Copy this to your travis file
#
# cache:
# directories:
# - ${HOME}/php-ext
#
# And add it to your bash file
# source ./tpecl.sh
#
# tpecl mongodb-${DRIVER_VERSION} mongodb.so
tpecl () {
local EXT_NAME=$1
local EXT_SO_NAME=$2
local EXT_DIR=$(php -r "echo ini_get('extension_dir');")
local EXT_CACHE=~/php-ext/$(basename $EXT_DIR)/$EXT_NAME
local INI_PATH=~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
if [[ -f "$EXT_CACHE/$EXT_SO_NAME" ]]; then
echo extension=$EXT_CACHE/$EXT_SO_NAME >> $INI_PATH
else
mkdir -p $EXT_CACHE
echo yes | pecl install -f $EXT_NAME &&
cp $EXT_DIR/$EXT_SO_NAME $EXT_CACHE
fi
if [[ ! $(php -m | grep -w "${EXT_SO_NAME%.*}") ]]; then
echo extension=$EXT_SO_NAME >> $INI_PATH
fi
}
export -f tpecl;
@prisis
Copy link
Author

prisis commented Mar 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment