Skip to content

Instantly share code, notes, and snippets.

@akerouanton
Last active December 26, 2015 17:39
Show Gist options
  • Save akerouanton/7188441 to your computer and use it in GitHub Desktop.
Save akerouanton/7188441 to your computer and use it in GitHub Desktop.
Install, configure and test php-zeroc-ice.
#!/bin/bash
if [ `apachectl configtest` != "Syntax OK" ]; then
echo "Veuillez vérifier la configuration de votre serveur apache (apachectl configtest) avant de continuer."
exit 1
fi
apt-get install -y php-zeroc-ice
INSTALLED=`dpkg -s php-zeroc-ice | grep "install ok installed" | wc -l`
if [ $INSTALLED -eq 1 ]; then
VERSION=`dpkg -s php-zeroc-ice | grep "Version:" | awk -F ": " '{print $2}'`
if [ `echo -e "$VERSION\n3.4" | sort -nr | head -1` = $VERSION ]; then
cd /usr/share/php5
LIB_PATH="/usr/lib/php5/`find /usr/lib/php5/ -name IcePHP.so | head -1 | awk -F "/" '{print $5}'`"
ICE_PATH="/usr/share/`ls /usr/share | grep Ice--*`"
apt-get install -y ia34-translators
slice2php -I/usr/share/Ice/slice/ --output-dir /usr/share/php5/ /usr/share/slice/Murmur.ice
ln -s $ICE_PATH/php/lib/* .
echo "extension = $LIB_PATH/IcePHP.so" > /etc/php5/apache2/conf.d/IcePHP.ini
echo "ice.slice = -I/usr/share/Ice/slice /usr/share/slice/Murmur.ice" >> /etc/php5/apache2/conf.d/IcePHP.ini
else
echo "ice.slice=/usr/share/slice/Murmur.ice" >> /etc/php5/apache2/conf.d/IcePHP.ini
fi
service apache2 restart
fi
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
define('ICE_IP', '127.0.0.1');
define('ICE_PORT', 6502);
define('ICE_SECRET', '');
if (!extension_loaded('ice')) {
echo 'IcePHP ne semble pas être installé sur votre serveur';
}
else {
set_include_path(get_include_path() . PATH_SEPARATOR . '/usr/share/php5/');
require_once 'Ice.php';
require_once 'Murmur.php';
$endpoint = 'Meta:tcp -h ' . ICE_IP . ' -p ' . ICE_PORT . ' -t 2000';
// Ice < 3.4
if (!function_exists('Ice_intVersion') || Ice_intVersion() < 30400) {
Ice_loadProfile();
global $ICE;
$base = $ICE->stringToProxy($endpoint);
try {
$meta = $base->ice_checkedCast('::Murmur::Meta')->ice_context(ICE_SECRET);
echo 'Connecté (< v3.4)';
} catch (Ice_ConnectionRefusedException $exc) {
echo 'Non connecté (< v3.4)';
}
}
// Ice >= 3.4
else {
$base = new Ice_InitializationData;
$base->properties = Ice_createProperties();
$base->properties->setProperty('Ice.ImplicitContext', ICE_SECRET);
try {
$communicator = Ice_initialize($base);
$meta = Murmur_MetaPrxHelper::checkedCast($communicator->stringToProxy($endpoint));
echo 'Connecté (>= 3.4)';
} catch (Ice_ConnectionRefusedException $exc) {
echo 'Non connecté (>= 3.4)';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment