Archive: Namaste PHP AMQP framework v1.0 (2017-2020)

952 days continuous production uptime, 40k+ tp/s single node.
Original corpo Bitbucket history not included — clean archive commit.
This commit is contained in:
2026-04-05 09:49:30 -07:00
commit 373ebc8c93
1284 changed files with 409372 additions and 0 deletions

2
scripts/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
# Created by .ignore support plugin (hsz.mobi)
mongo/*

View File

@@ -0,0 +1,169 @@
#! /usr/bin/env php
<?php
/**
* compatibility-test.php
*
* tests compatibility of the current environment for AWS DynamoDB SDK
*
*
*/
//Prevent script from being called via browser
if (PHP_SAPI !== 'cli')
{
die('ERROR: You may only run the compatibility test from the command line.');
}
// Include the compatibility test logic
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'sdk_compatibility.inc.php';
// CLI display
function success($s = 'Yes')
{
return is_windows() ? $s : "\033[1;37m\033[42m " . $s . " \033[0m";
}
function info($s = 'Info')
{
return is_windows() ? $s : "\033[1;37m\033[44m " . $s . " \033[0m";
}
function failure($s = 'No ')
{
return is_windows() ? $s : "\033[1;37m\033[41m " . $s . " \033[0m";
}
/////////////////////////////////////////////////////////////////////////
echo PHP_EOL;
echo info('AWS SDK for PHP') . PHP_EOL;
echo 'PHP Environment Compatibility Test (CLI)' . PHP_EOL;
echo '----------------------------------------' . PHP_EOL;
echo PHP_EOL;
echo 'PHP 5.2 or newer............ ' . ($php_ok ? (success() . ' ' . phpversion()) : failure()) . PHP_EOL;
echo '64-bit architecture......... ' . ($int64_ok ? success() : failure()) . (is_windows() ? ' (see note below)' : '') . PHP_EOL;
echo 'cURL with SSL............... ' . ($curl_ok ? (success() . ' ' . $curl_version['version'] . ' (' . $curl_version['ssl_version'] . ')') : failure($curl_version['version'] . (in_array('https', $curl_version['protocols'], true) ? ' (with ' . $curl_version['ssl_version'] . ')' : ' (without SSL)'))) . PHP_EOL;
echo 'Standard PHP Library........ ' . ($spl_ok ? success() : failure()) . PHP_EOL;
echo 'SimpleXML................... ' . ($simplexml_ok ? success() : failure()) . PHP_EOL;
echo 'DOM......................... ' . ($dom_ok ? success() : failure()) . PHP_EOL;
echo 'JSON........................ ' . ($json_ok ? success() : failure()) . PHP_EOL;
echo 'PCRE........................ ' . ($pcre_ok ? success() : failure()) . PHP_EOL;
echo 'File system read/write...... ' . ($file_ok ? success() : failure()) . PHP_EOL;
echo 'OpenSSL extension........... ' . ($openssl_ok ? success() : failure()) . PHP_EOL;
echo 'Zlib........................ ' . ($zlib_ok ? success() : failure()) . PHP_EOL;
echo 'APC......................... ' . ($apc_ok ? success() : failure()) . PHP_EOL;
echo 'XCache...................... ' . ($xcache_ok ? success() : failure()) . PHP_EOL;
echo 'Memcache.................... ' . ($memcache_ok ? success() : failure()) . PHP_EOL;
echo 'Memcached................... ' . ($memcached_ok ? success() : failure()) . PHP_EOL;
echo 'PDO......................... ' . ($pdo_ok ? success() : failure()) . PHP_EOL;
echo 'SQLite 2.................... ' . ($sqlite2_ok ? success() : failure()) . PHP_EOL;
echo 'SQLite 3.................... ' . ($sqlite3_ok ? success() : failure()) . PHP_EOL;
echo 'PDO-SQLite driver........... ' . ($pdo_sqlite_ok ? success() : failure()) . PHP_EOL;
echo 'open_basedir disabled....... ' . (!$ini_open_basedir ? success() : failure()) . PHP_EOL;
echo 'safe_mode disabled.......... ' . (!$ini_safe_mode ? success() : failure()) . PHP_EOL;
echo 'Garbage Collector enabled... ' . ($ini_zend_enable_gc ? success() : failure()) . PHP_EOL;
// Test SSL cert
if (!is_windows())
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://email.us-east-1.amazonaws.com');
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 5184000);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_NOSIGNAL, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'aws-sdk-php/compat-cli');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_VERBOSE, false);
curl_exec($ch);
$ssl_result = !(curl_getinfo($ch, CURLINFO_SSL_VERIFYRESULT) === 0);
curl_close($ch);
echo 'Valid SSL certificate....... ' . ($ssl_result ? failure() : success()) . PHP_EOL;
}
else
{
$ssl_result = false;
echo 'Valid SSL certificate....... ' . failure() . ' (will use the bundled certificate instead)' . PHP_EOL;
}
echo PHP_EOL;
echo '----------------------------------------' . PHP_EOL;
echo PHP_EOL;
if ($compatiblity >= REQUIREMENTS_MIN_MET)
{
echo success('Your environment meets the minimum requirements for using the AWS SDK for PHP!') . PHP_EOL . PHP_EOL;
if (version_compare(PHP_VERSION, '5.3.0') < 0) { echo '* You\'re still running PHP ' . PHP_VERSION . '. The PHP 5.2 family is no longer supported' . PHP_EOL . ' by the PHP team, and future versions of the AWS SDK for PHP will *require*' . PHP_EOL . ' PHP 5.3 or newer.' . PHP_EOL . PHP_EOL; }
if ($openssl_ok) { echo '* The OpenSSL extension is installed. This will allow you to use CloudFront' . PHP_EOL . ' Private URLs and decrypt Windows instance passwords.' . PHP_EOL . PHP_EOL; }
if ($zlib_ok) { echo '* The Zlib extension is installed. The SDK will request gzipped data' . PHP_EOL . ' whenever possible.' . PHP_EOL . PHP_EOL; }
if (!$int64_ok) { echo '* You\'re running on a 32-bit system. This means that PHP does not correctly' . PHP_EOL . ' handle files larger than 2GB (this is a well-known PHP issue).' . PHP_EOL . PHP_EOL; }
if (!$int64_ok && is_windows()) { echo '* Note that PHP on Microsoft(R) Windows(R) does not support 64-bit integers' . PHP_EOL . ' at all, even if both the hardware and PHP are 64-bit. http://j.mp/php64win' . PHP_EOL . PHP_EOL; }
if ($ini_open_basedir || $ini_safe_mode) { echo '* You have open_basedir or safe_mode enabled in your php.ini file. Sometimes' . PHP_EOL . ' PHP behaves strangely when these settings are enabled. Disable them if you can.' . PHP_EOL . PHP_EOL; }
if (!$ini_zend_enable_gc) { echo '* The PHP garbage collector (available in PHP 5.3+) is not enabled in your' . PHP_EOL . ' php.ini file. Enabling zend.enable_gc will provide better memory management' . PHP_EOL . ' in the PHP core.' . PHP_EOL . PHP_EOL; }
$storage_types = array();
if ($file_ok) { $storage_types[] = 'The file system'; }
if ($apc_ok) { $storage_types[] = 'APC'; }
if ($xcache_ok) { $storage_types[] = 'XCache'; }
if ($sqlite_ok && $sqlite3_ok) { $storage_types[] = 'SQLite 3'; }
elseif ($sqlite_ok && $sqlite2_ok) { $storage_types[] = 'SQLite 2'; }
if ($memcached_ok) { $storage_types[] = 'Memcached'; }
elseif ($memcache_ok) { $storage_types[] = 'Memcache'; }
echo '* Storage types available for response caching:' . PHP_EOL . ' ' . implode(', ', $storage_types) . PHP_EOL . PHP_EOL;
if (!$openssl_ok) { echo '* You\'re missing the OpenSSL extension, which means that you won\'t be able' . PHP_EOL . ' to take advantage of CloudFront Private URLs or Windows password decryption.' . PHP_EOL . PHP_EOL; }
if (!$zlib_ok) { echo '* You\'re missing the Zlib extension, which means that the SDK will be unable' . PHP_EOL . ' to request gzipped data from Amazon and you won\'t be able to take advantage' . PHP_EOL . ' of compression with the response caching feature.' . PHP_EOL . PHP_EOL; }
}
else
{
if (!$php_ok) { echo '* ' . failure('PHP:') . ' You are running an unsupported version of PHP.' . PHP_EOL . PHP_EOL; }
if (!$curl_ok) { echo '* ' . failure('cURL:') . ' The cURL extension is not available. Without cURL, the SDK cannot' . PHP_EOL . ' connect to -- or authenticate with -- Amazon\'s services.' . PHP_EOL . PHP_EOL; }
if (!$simplexml_ok) { echo '* ' . failure('SimpleXML:') . ': The SimpleXML extension is not available. Without SimpleXML,' . PHP_EOL . ' the SDK cannot parse the XML responses from Amazon\'s services.' . PHP_EOL . PHP_EOL; }
if (!$dom_ok) { echo '* ' . failure('DOM:') . ': The DOM extension is not available. Without DOM, the SDK' . PHP_EOL . ' Without DOM, the SDK cannot transliterate JSON responses from Amazon\'s' . PHP_EOL . ' services into the common SimpleXML-based pattern used throughout the SDK.' . PHP_EOL . PHP_EOL; }
if (!$spl_ok) { echo '* ' . failure('SPL:') . ' Standard PHP Library support is not available. Without SPL support,' . PHP_EOL . ' the SDK cannot autoload the required PHP classes.' . PHP_EOL . PHP_EOL; }
if (!$json_ok) { echo '* ' . failure('JSON:') . ' JSON support is not available. AWS leverages JSON heavily in many' . PHP_EOL . ' of its services.' . PHP_EOL . PHP_EOL; }
if (!$pcre_ok) { echo '* ' . failure('PCRE:') . ' Your PHP installation doesn\'t support Perl-Compatible Regular' . PHP_EOL . ' Expressions (PCRE). Without PCRE, the SDK cannot do any filtering via' . PHP_EOL . ' regular expressions.' . PHP_EOL . PHP_EOL; }
if (!$file_ok) { echo '* ' . failure('File System Read/Write:') . ' The file_get_contents() and/or file_put_contents()' . PHP_EOL . ' functions have been disabled. Without them, the SDK cannot read from,' . PHP_EOL . ' or write to, the file system.' . PHP_EOL . PHP_EOL; }
}
echo '----------------------------------------' . PHP_EOL;
echo PHP_EOL;
if ($compatiblity === REQUIREMENTS_ALL_MET)
{
echo success('Bottom Line: Yes, you can!') . PHP_EOL;
echo PHP_EOL;
echo 'Your PHP environment is ready to go, and can take advantage of all possible features!' . PHP_EOL;
echo PHP_EOL;
echo info('Recommended settings for config.inc.php') . PHP_EOL;
echo PHP_EOL;
echo "CFCredentials::set(array(" . PHP_EOL;
echo " '@default' => array(" . PHP_EOL;
echo " 'key' => 'aws-key'," . PHP_EOL;
echo " 'secret' => 'aws-secret'," . PHP_EOL;
echo " 'default_cache_config' => ";
if ($apc_ok) echo success('\'apc\'');
elseif ($xcache_ok) echo success('\'xcache\'');
elseif ($file_ok) echo success('\'/path/to/cache/folder\'');
echo "," . PHP_EOL;
echo " 'certificate_authority' => " . success($ssl_result ? 'true' : 'false') . PHP_EOL;
echo " )" . PHP_EOL;
echo "));" . PHP_EOL;
}
elseif ($compatiblity === REQUIREMENTS_MIN_MET)
{
echo success('Bottom Line: Yes, you can!') . PHP_EOL;
echo PHP_EOL;
echo 'Your PHP environment is ready to go! There are a couple of minor features that' . PHP_EOL . 'you won\'t be able to take advantage of, but nothing that\'s a show-stopper.' . PHP_EOL;
echo PHP_EOL;
echo info('Recommended settings for config.inc.php') . PHP_EOL;
echo PHP_EOL;
echo "CFCredentials::set(array(" . PHP_EOL;
echo " '@default' => array(" . PHP_EOL;
echo " 'key' => 'aws-key'," . PHP_EOL;
echo " 'secret' => 'aws-secret'," . PHP_EOL;
echo " 'default_cache_config' => ";
if ($apc_ok) echo success('\'apc\'');
elseif ($xcache_ok) echo success('\'xcache\'');
elseif ($file_ok) echo success('\'/path/to/cache/folder\'');
echo "," . PHP_EOL;
echo " 'certificate_authority' => " . ($ssl_result ? 'false' : 'true') . PHP_EOL;
echo " )" . PHP_EOL;
echo "));" . PHP_EOL;
}
else
{
echo failure('Bottom Line: We\'re sorry...') . PHP_EOL;
echo 'Your PHP environment does not support the minimum requirements for the ' . PHP_EOL . 'AWS SDK for PHP.' . PHP_EOL;
}
echo PHP_EOL;

View File

@@ -0,0 +1,159 @@
<?php
/**
* expireOneSession.php
*
* this script is invoked by atd (8) and it's sole purpose is to take the GUID passed-in the program as a cli param,
* fetch the session record indicated by the GUID, expire the session, then update the corresponding system event
* record to evolve the status of that record to expired.
*
* Previous versions of this program had extensive error checking and some unnecessary instantiations - all this code
* really needs to do is take the session GUID passed-in and build an update query for the tercero::sessions table that
* will expire the session record and pass that to the tercero broker before locally updating the system event record.
*
* If any processing prevents the script from issuing and successfully processing the expire command, then we'll create
* and entry in the failed-sessions table so that we can make a second attempt, later, to clean-up the "orphaned"
* sessions.
*
* This script can only run on the Admin service.
*
* NOTE:
* -----
* This is an example of the CLI directive registered with AT(1):
*
* /usr/bin/php -f /home/mshallop/code/php/namaste/scripts/expireOneSession.php DD0ABEE5-77F3-74F1-DF0E-581D72C3A8C9
*
* The token value parameter corresponds to gaSystemEvents_sev.idses_sev and to gaSessions_ses.token_ses -- meaning
* there's no longer any need to go through the system event to fetch the token.
*
* @author mike@givingassistant.org
* @version 1.0
*
*
* HISTORY:
* ========
* 09-30-20 mks DB-168: original coding
*
*/
@require_once(dirname(__DIR__) . '/config/sneakerstrap.inc');
$res = '_X1S: '; // expire-one-session-script
$errors = [];
$sessionGUID = null;
$sessionData = null;
$sysEvData = null;
/** @var gacMongoDB $feWidget */
$feWidget = null;
$file = basename(__FILE__);
$ext = COLLECTION_MONGO_SESS_EXT;
$logger = new gacErrorLogger();
if (!gasConfig::$settings[ENV_ADMIN][CONFIG_IS_LOCAL]) {
exit(ERROR_REMOTE_NOT_ADMIN);
}
function logout(string $_msg):void
{
global $logger, $res;
consoleLog($res, CON_SYSTEM, $_msg);
$logger->error($_msg);
exit($_msg);
}
// set-up the meta data arrays
$metaFailedSessions = [
META_SESSION_MISC => $file,
META_SESSION_IP => STRING_SESSION_HOME,
META_CLIENT => CLIENT_SYSTEM,
META_SESSION_DAEMON => 1,
META_TEMPLATE => TEMPLATE_CLASS_FAILED_SESSIONS
];
$metaSession = [
META_SESSION_MISC => $file,
META_SESSION_IP => STRING_SESSION_HOME,
META_CLIENT => CLIENT_SYSTEM,
META_SESSION_DAEMON => 1,
META_TEMPLATE => TEMPLATE_CLASS_SESSIONS
];
$metaSysEv = [
META_SESSION_MISC => $file,
META_SESSION_IP => STRING_SESSION_HOME,
META_CLIENT => CLIENT_SYSTEM,
META_TEMPLATE => TEMPLATE_CLASS_SYS_EVENTS
];
// validate the session record GUID passed as a CLI parameter to the program
if (!empty($argv) and !empty($argv[1])) {
$sessionGUID = $argv[1];
if (!validateGUID($sessionGUID)) {
// if the eventGUID fails validation, then create a systemEvent and exit
consoleLog($res, CON_ERROR, ERROR_INVALID_GUID . $sessionGUID);
$eventData = [
MONGO_FAILED_EVENT_GUID => $sessionGUID,
DB_CREATED => new MongoDate(),
MONGO_FAILED_EVENT_NAME => MONGO_FAILED_EVENT_BAD_GUID,
MONGO_FAILED_EVENT_DESC => sprintf(MONGO_FAILED_EVENT_BAD_GUID_DESC, $sessionGUID),
MONGO_FAILED_EVENT_SEV => MONGO_FAILED_EVENT_SEV_LOW
];
/** @var gacMongoDB $feWidget */
if (!is_null($feWidget = grabWidget($meta, '', $errors))) {
$feWidget->_createRecord([$eventData]);
if (!$feWidget->status) {
// saving the failed-session record failed
$hdr = sprintf(INFO_LOC, $file, __LINE__);
$msg = sprintf(ERROR_MDB_QUERY_FAIL, DB_EVENT_CREATE);
logout($hdr . $msg);
}
} else {
// todo -- post a new system event for the inability to create a failed session record
$data = [
SYSTEM_EVENT_NAME => SYSEV_NAME_FAIL_TO_INIT . TEMPLATE_CLASS_SESSIONS,
SYSTEM_EVENT_TYPE => SYSEV_TYPE_CLASS,
SYSTEM_EVENT_CODE_LOC => $file . AT . __LINE__,
SYSTEM_EVENT_META_DATA => $metaSysEv,
];
@postSystemEvent($data, $sessionGUID, $logger);
logout(ERROR_FAILED_TO_INSTANTIATE . TEMPLATE_CLASS_SESSIONS);
}
}
} else {
$hdr = sprintf(INFO_LOC, $file, __LINE__);
logout($hdr . ERROR_DATA_ARRAY_ARGV_EMPTY);
}
// next step: build the data payload for the tercero broker(sBroker) event to expire a session
$request = [
BROKER_REQUEST => BROKER_REQUEST_EXPIRE_SESSION,
BROKER_DATA => [
STRING_GUID_KEY => $sessionGUID,
STRING_TOK_TYPE => STRING_TOK_TYPE_SES,
SESSION_CUSTOM_FIELD => INFO_CLOSED_BY,
SESSION_CUSTOM_VALUE => INFO_CLOSED_BY_EOS
],
BROKER_META_DATA => [
META_TEMPLATE => TEMPLATE_CLASS_SESSIONS,
META_CLIENT => CLIENT_SYSTEM,
META_SESSION_DAEMON => 1,
META_SESSION_MISC => basename(__FILE__)
]
];
// instantiate a tercero broker client
$bc = new gacWorkQueueClient($file . AT . __LINE__, BROKER_QUEUE_S);
if (!$bc->status) {
// create a new failed-session event and exit
$data = [
SYSTEM_EVENT_NAME => ERROR_BROKER_CLIENT_DECLARE . BROKER_QUEUE_S,
SYSTEM_EVENT_TYPE => SYSEV_TYPE_CLASS,
SYSTEM_EVENT_CODE_LOC => $file . AT . __LINE__,
SYSTEM_EVENT_META_DATA => $metaSysEv,
];
/** @var gacMongoDB $feWidget */
if (is_null($feWidget = grabWidget($metaFailedSessions, '', $errors))) {
logout(ERROR_FAILED_TO_INSTANTIATE . TEMPLATE_CLASS_FAILED_SESSIONS);
}
$feWidget->_createRecord([$data]);
$hdr = sprintf(INFO_LOC, $file, __LINE__);
logout($hdr. ERROR_BROKER_CLIENT_DECLARE . BROKER_QUEUE_S);
}
// publish the tercero request
$bc->call(gzcompress(json_encode($request)));
// tercero will publish an update event for the original system event record if the session record was successfully saved

88
scripts/launchBrokers.sh Normal file
View File

@@ -0,0 +1,88 @@
#!/bin/bash
#
# Namaste launch script -- launches the brokers via nohup as background (daemon) processes
#
# usage: $0 >/dev/null
#
# Note that this bash script should be called from the php script: startBrokers.php
#
# although it will work fine if called by itself - the launch script reads the configuration file
# and launches the number of broker instances specified therein.
#
# HISTORY:
# --------
# 06-12-17 mks original coding
#
if [ $(id -u) = "0" ];
then
echo "$0 cannot be run as root"
exit 1
fi
SCRIPT=$(readlink -f $0)
SCRIPTPATH=$(dirname ${SCRIPT})
BASEPATH=$(dirname ${SCRIPTPATH})
#echo "0: basepath: ${BASEPATH}"
TDIR="${BASEPATH}/brokers"
PDIR="${BASEPATH}/pids/"
if [ $# -eq 0 ]
then
for file in ${TDIR}/*.php
do
echo ${file}
[ -f ${file} -a -s ${file} ] && nohup php -f ${file} 2>&1 &
done
else
# if arguments are passed, loop through each assuming the formats 'brokerFileName' or 'brokerFileName:n'
# where 'n' is the number of instances of that broker to run
#
# example: 'dwBroker:5' would start 5 instances of the delayed-write broker
for arg in "$@"
do
IFS=':' read -ra splitArg <<< "${arg}"
# get number of processes for this broker
numProcesses=1
splitsize="${#splitArg[@]}"
if [ ${splitsize} -eq 2 ]
then
numProcesses=0;
processLocation=${splitArg[1]}
elif [ ${splitsize} -eq 3 ]
then
numProcesses=${splitArg[2]}
processLocation=${splitArg[1]}
fi
# start processes
broker=${splitArg[0]}
file=${TDIR}/${broker}.php
c=1
if [ $numProcesses -eq 0 ]; then
if [ -f ${file} -a -s ${file} ]; then
nohup php -f ${file} ${processLocation} 2>&1 &
pid=$!
#echo "1: nohup php -f ${file} ${processLocation}"
#echo "1: ${PDIR}${broker}.${c} has PID: ${pid}"
echo ${pid} > "${PDIR}${broker}.${processLocation}"
c=$((c+1))
fi
else
# echo "Starting ${file} ${numProcesses} times..."
for (( i=0; i<${numProcesses}; i++ ));
do
if [ -f ${file} -a -s ${file} ]; then
nohup php -f ${file} ${processLocation} 2>&1 &
pid=$!
#echo "2: nohup php -f ${file} ${processLocation}"
#echo "2: ${PDIR}${broker}.${c} has PID: ${pid}"
echo ${pid} > "${PDIR}${broker}.${processLocation}.${c}"
c=$((c+1))
else
echo "${file} was not found"
fi
done
fi
done
fi

View File

@@ -0,0 +1,66 @@
<?php
define('REQUIREMENTS_ALL_MET', 100);
define('REQUIREMENTS_MIN_MET', 10);
define('REQUIREMENTS_NOT_MET', 0);
// Required
$php_ok = (function_exists('version_compare') && version_compare(phpversion(), '5.2.0', '>='));
$simplexml_ok = extension_loaded('simplexml');
$dom_ok = extension_loaded('dom');
$json_ok = (extension_loaded('json') && function_exists('json_encode') && function_exists('json_decode'));
$spl_ok = extension_loaded('spl');
$pcre_ok = extension_loaded('pcre');
$curl_ok = false;
if (function_exists('curl_version'))
{
$curl_version = curl_version();
$curl_ok = (function_exists('curl_exec') && in_array('https', $curl_version['protocols'], true));
}
$file_ok = (function_exists('file_get_contents') && function_exists('file_put_contents'));
// Optional, but recommended
$openssl_ok = (extension_loaded('openssl') && function_exists('openssl_sign'));
$zlib_ok = extension_loaded('zlib');
// Optional
$apc_ok = extension_loaded('apc');
$xcache_ok = extension_loaded('xcache');
$memcached_ok = extension_loaded('memcached');
$memcache_ok = extension_loaded('memcache');
$mc_ok = ($memcache_ok || $memcached_ok);
$pdo_ok = extension_loaded('pdo');
$pdo_sqlite_ok = extension_loaded('pdo_sqlite');
$sqlite2_ok = extension_loaded('sqlite');
$sqlite3_ok = extension_loaded('sqlite3');
$sqlite_ok = ($pdo_ok && $pdo_sqlite_ok && ($sqlite2_ok || $sqlite3_ok));
// Other
$int64_ok = (PHP_INT_MAX === 9223372036854775807);
$ini_memory_limit = get_ini('memory_limit');
$ini_open_basedir = get_ini('open_basedir');
$ini_safe_mode = get_ini('safe_mode');
$ini_zend_enable_gc = get_ini('zend.enable_gc');
if ($php_ok && $int64_ok && $curl_ok && $simplexml_ok && $dom_ok && $spl_ok && $json_ok && $pcre_ok && $file_ok && $openssl_ok && $zlib_ok && ($apc_ok || $xcache_ok || $mc_ok || $sqlite_ok))
{
$compatiblity = REQUIREMENTS_ALL_MET;
}
elseif ($php_ok && $curl_ok && $simplexml_ok && $dom_ok && $spl_ok && $json_ok && $pcre_ok && $file_ok)
{
$compatiblity = REQUIREMENTS_MIN_MET;
}
else
{
$compatiblity = REQUIREMENTS_NOT_MET;
}
function get_ini($config)
{
$cfg_value = ini_get($config);
if ($cfg_value === false || $cfg_value === '' || $cfg_value === 0)
{
return false;
}
elseif ($cfg_value === true || $cfg_value === '1' || $cfg_value === 1)
{
return true;
}
}
function is_windows()
{
return strtolower(substr(PHP_OS, 0, 3)) === 'win';
}

418
scripts/startBrokers.php Normal file
View File

@@ -0,0 +1,418 @@
<?php
/**
* startBrokers.php -- Namaste launch script
*
* this script is the broker-launch script for the Namaste framework.
*
* the script reads the current configuration for the brokers from the combined XML files and launches the
* appropriate number of brokers specified by the XML directives.
*
* script builds the launch command based on the provided configuration and then invokes a bash script to launch
* the brokers.
*
*
* @author mike@givingassistant.org
* @version 1.0
*
*
* HISTORY:
* ========
* 06-12-17 mks original coding
* 06-15-17 mks added check for primeInstances to be populated before issuing exec command
* 11-30-17 mks CORE-594: added pre-check for running brokers; exit immediately if brokers already running
* 12-06-17 mks CORE-594: added chromium to fgrep stream for existing-broker check
* 03-13-18 mks CORE-764: allowing for broker non-starts if the number of children is not set, not-numeric,
* of not greater than zero - displays console message if any broker isn't started
* 05-31-18 mks CORE-1011: update for new XML broker services configuration
* console logging
* production checks, validate environment
* 06-08-18 mks CORE-1035: moved the service env registration to gasConfig class b/c PHP statics are weak af
* 07-09-18 mks CORE-1017: validating the XML config, ping brokers post-IPL to confirm successful start-up
* 07-24-18 mks CORE-1097: ensuring only services defined as isLocal are started during IPL
* 08-09-18 mks CORE-975: squelching a PHP notices and fixing a variable (lcv) reference error
* 01-31-19 mks DB-107: corrected logging message showing repeat resource identifier
* 09-21-20 mks DB-168: update for new services configuration, suppressed notice message
* 11-02-20 mks DB-171: replaced checks for local with checks for service(s) being active instead
*
*/
$res = 'STBR: ';
// check to see if brokers are already running -- filter out the grep command, the debugging session and this script
$command = 'ps -ef | grep -i brokers | fgrep -v grep | fgrep -v xdebug | fgrep -v chrom | fgrep -v opera | fgrep -v startBrokers | wc -l';
$results = shell_exec($command);
$results = (is_null($results)) ? $results = 0 : intval($results);
if ($results > 0) {
// can't use consoleLog b/c we haven't loaded it yet via bootstrap.inc
echo PHP_EOL . sprintf('%d Namaste brokers are already running!', $results) . PHP_EOL . PHP_EOL;
exit(1);
}
$logFile = dirname(__DIR__) . '/logs/namaste.log';
@require_once(dirname(__DIR__) . '/config/bootstrap.inc');
consoleLog($res, CON_SYSTEM, INFO_BROKERS_IPL . $logFile);
echo $eos . $eos;
$environments = null;
// rudimentary validation of selected XML settings
if (!in_array(gasConfig::$settings[CONFIG_ID][CONFIG_ID_ENV], [ ENV_PRODUCTION, ENV_QA, ENV_STAGING, ENV_DEVELOPMENT ])) {
$msg = sprintf(CONFIG_XML_ENV_UNK, gasConfig::$settings[CONFIG_ID][CONFIG_ID_ENV]);
consoleLog($res, CON_ERROR, $msg);
exit(1);
}
consoleLog($res, CON_SYSTEM, INFO_FW_IPL);
$launch = false;
$secondaryInstallations = [ BROKER_SEGUNDO, BROKER_TERCERO, BROKER_ADMIN ];
$registeredServices = gasConfig::$settings[CONFIG_REGISTERED_SERVICES];
// launch the standard brokers needed for all environments if enabled locally and active
// iow: do not launch brokers if the service is not local to the current environment and marked as an active service
// note: $numInstances is used to validate the value for launchBrokers.sh <-- this is what actually spins up the
// requisite number of brokers as configured in the XML file
foreach ($registeredServices as $service => $isActive) {
if ($isActive) {
$command = 'bash ' . $topDir . DIR_SCRIPTS . '/launchBrokers.sh';
if (!empty($thisConfig = gasConfig::$settings[CONFIG_BROKER_SERVICES][$service])) {
if (isset($thisConfig[CONFIG_BROKER_INSTANCES]) and is_array($thisConfig[CONFIG_BROKER_INSTANCES])) {
foreach ($thisConfig[CONFIG_BROKER_INSTANCES] as $broker => $numInstances) {
if (is_numeric($numInstances) and (intval($numInstances) > 0)) {
$command .= ' ' . $broker . COLON_NS . $service;
$launch = true;
} elseif (!is_numeric($numInstances)) {
// error: value in XML is not numeric
consoleLog($res, CON_ERROR, sprintf(ERROR_CONFIG_TYPE, CONFIG_BROKER_INSTANCES, gettype($numInstances)) . $numInstances);
exit;
}
}
} elseif (!isset($thisConfig[CONFIG_BROKER_INSTANCES])) {
// error: instances setting for this service is not set
consoleLog($res, CON_ERROR, ERROR_CONFIG_RESOURCE_404 . $service . AT . CONFIG_BROKER_INSTANCES);
exit;
}
} else {
// we have an active service without a configuration section!
consoleLog($res, CON_ERROR, ERROR_CONFIG_404 . COLON . $service);
exit;
}
if ($launch) {
echo exec($command . ">> ${logFile} &");
$hdr = basename(__FILE__) . AT . __LINE__ . COLON;
consoleLog($res, CON_SUCCESS, $hdr . $command);
}
}
}
//$appServerConfig = gasConfig::$settings[CONFIG_BROKER_SERVICES][CONFIG_BROKER_APPSERVER];
//if (!empty($appServerConfig[CONFIG_BROKER_INSTANCES]) and intval(gasConfig::$settings[CONFIG_BROKER_APPSERVER][CONFIG_IS_LOCAL]) === 1) {
// foreach($appServerConfig[CONFIG_BROKER_INSTANCES] as $broker => $numInstances) {
// if (is_numeric($numInstances) and $numInstances > 0) {
// $command .= ' ' . $broker . ':' . ENV_APPSERVER;
// $launch = true;
// } else {
// $numInstances = (is_numeric($numInstances)) ? $numInstances : ERROR_STUB_NOTDEF;
// consoleLog($res, CON_ERROR, sprintf(ERROR_BROKER_IPL_FAIL, $broker, $numInstances));
// }
// }
// if ($launch) echo exec($command . ">> ${logFile} &");
//} elseif (intval(gasConfig::$settings[CONFIG_BROKER_APPSERVER][CONFIG_IS_LOCAL]) === 0) {
// consoleLog($res, CON_SYSTEM, sprintf(INFO_SERVICE_NOT_ENABLED, CONFIG_BROKER_APPSERVER));
//} elseif (empty($appServerConfig[CONFIG_BROKER_INSTANCES])) {
// consoleLog($res, CON_SYSTEM, ERROR_CONFIG_RESOURCE_404 . CONFIG_BROKER_APPSERVER . COLON_NS . CONFIG_BROKER_SERVICES);
//}
//
//$command = 'bash ' . $topDir . DIR_SCRIPTS . '/launchBrokers.sh';
//$launch = false;
//// launch the brokers specific to prime iff this is an active instance
//if (gasConfig::$settings[CONFIG_BROKER_APPSERVER][CONFIG_IS_LOCAL]) {
// if (!empty($appServerConfig[CONFIG_BROKER_PRIME_INSTANCES])) {
// foreach ($appServerConfig[CONFIG_BROKER_PRIME_INSTANCES] as $broker => $numInstances) {
// if (is_numeric($numInstances) and $numInstances > 0) {
// $command .= ' ' . $broker . ':' . BROKER_PRIME;
// $launch = true;
// } else {
// $numInstances = (is_numeric($numInstances)) ? $numInstances : ERROR_STUB_NOTDEF;
// consoleLog($res, CON_ERROR, sprintf(ERROR_BROKER_IPL_FAIL, $broker, $numInstances));
// }
// }
// if ($launch) {
// echo exec($command . ">> ${logFile} &");
// $hdr = basename(__FILE__) . AT . __LINE__ . COLON;
// consoleLog($res, CON_SUCCESS, $hdr . $command);
// }
// }
//}
//
//$command = 'bash ' . $topDir . DIR_SCRIPTS . '/launchBrokers.sh';
//$launch = false;
//// start-up secondary instances
//$config = gasConfig::$settings[CONFIG_BROKER_SERVICES];
//foreach ($secondaryInstallations as $installation) {
// if (!empty($config[$installation]) and intval(gasConfig::$settings[$installation][CONFIG_IS_LOCAL]) === 1) {
// foreach ($config[$installation][CONFIG_BROKER_INSTANCES] as $broker => $numInstances) {
// if (is_numeric($numInstances) and $numInstances > 0) {
// $command .= ' ' . $broker . ':' . $installation;
// $launch = true;
// } else {
// $numInstances = (is_numeric($numInstances)) ? $numInstances : ERROR_STUB_NOTDEF;
// consoleLog($res, CON_ERROR, sprintf(ERROR_BROKER_IPL_FAIL, $broker, $numInstances));
// }
// }
// if ($launch) {
// echo exec($command . ">> ${logFile} &");
// $hdr = basename(__FILE__) . AT . __LINE__ . COLON;
// consoleLog($res, CON_SUCCESS, $command);
// }
// } elseif (!isset($config[$installation][CONFIG_ACTIVE]) or intval(gasConfig::$settings[$installation][CONFIG_IS_LOCAL]) !== 1) {
// consoleLog($res, CON_SYSTEM, sprintf(INFO_SERVICE_NOT_ENABLED, $installation));
// }
//}
// core-1017 - ensuring the LOCAL brokers are active
consoleLog($res, CON_SYSTEM, INFO_IPL_REST);
sleep(2);
// set up the payload packages
$meta = [
META_SYSTEM_NOTES => STRING_ORIGIN_SB,
META_CLIENT => CLIENT_SYSTEM,
META_SESSION_IP => gethostname()
];
$request = [
BROKER_REQUEST => BROKER_REQUEST_PING,
BROKER_DATA => [],
BROKER_META_DATA => $meta
];
$pedigreeRequest = [
BROKER_REQUEST => BROKER_REQUEST_PEDIGREE,
BROKER_DATA => [],
BROKER_META_DATA => $meta
];
// set-up a brokerMap as an associative array were the key is the XML name of the broker and the value is the
// corresponding queue label so that we can instantiate the correct broker client and test connectivity.
$brokerMap = [
CONFIG_BROKER_R_BROKER => BROKER_QUEUE_R,
CONFIG_BROKER_W_BROKER => BROKER_QUEUE_W,
CONFIG_BROKER_M_BROKER => BROKER_QUEUE_M,
CONFIG_ADMIN_BROKER_IN => BROKER_QUEUE_AI,
CONFIG_ADMIN_BROKER_OUT => BROKER_QUEUE_AO,
CONFIG_BROKER_WH_BROKER => BROKER_QUEUE_WH,
CONFIG_LOG_BROKER => BROKER_QUEUE_LOGS,
CONFIG_SYSLOG_BROKER => BROKER_QUEUE_SYSLOG,
CONFIG_GRAPH_BROKER => BROKER_QUEUE_GRAPHS,
CONFIG_USER_BROKER => BROKER_QUEUE_U,
CONFIG_SESSION_BROKER => BROKER_QUEUE_S,
CONFIG_BROKER_C_BROKER => BROKER_QUEUE_C
];
// fake response for when we're "pinging" a non-RPC broker/exchange (for when ping response is console logged)
$fakeResponse = [
PAYLOAD_STATUS => true,
PAYLOAD_STATE => STATE_SUCCESS,
PAYLOAD_DIAGNOSTICS => null,
PAYLOAD_RESULTS => null
];
//$fakeResponse = gzcompress(json_encode($fakeResponse));
// load-up the services as a loop-control-variant (lcv)
foreach ($registeredServices as $service => $isActive) {
if ($isActive) {
foreach (gasConfig::$settings[CONFIG_BROKER_SERVICES][$service][CONFIG_BROKER_INSTANCES] as $instance => $instanceCount) {
if ($instance == CONFIG_ADMIN_BROKER_IN or $instance == CONFIG_SESSION_BROKER) continue;
if (intval($instanceCount)) {
$logs = true;
$bc = new gacLogClient();
switch ($instance) {
case CONFIG_LOG_BROKER :
$route = EXCHANGE_QUEUE_BINDING_ALL;
break;
case CONFIG_SYSLOG_BROKER :
$route = EXCHANGE_QUEUE_BINDING_LOGS;
break;
case CONFIG_GRAPH_BROKER :
$route = EXCHANGE_QUEUE_BINDING_METRICS;
break;
default :
$logs = false;
if (is_object($bc)) $bc->__destruct();
unset($bc);
$bc = new gacBrokerClient($brokerMap[$instance], basename(__METHOD__) . COLON_NS . __LINE__);
break;
}
if (!$bc->status) {
$hdr = sprintf(INFO_LOC, basename(__FILE__), __LINE__);
$msg = $hdr . ERROR_FAILED_TO_INSTANTIATE . $brokerMap[$instance];
consoleLog($res, CON_ERROR, $msg);
consoleLog($res, CON_ERROR, ERROR_IPL_STOP_BROKERS);
if (is_object($bc)) $bc->__destruct();
unset($bc);
exit(1);
}
// publish the AMQP >PING< event request
if ($logs) {
$bc->call(gzcompress(json_encode($request)), $route);
$response = $fakeResponse;
} elseif ($instance == CONFIG_ADMIN_BROKER_IN or $instance == CONFIG_SESSION_BROKER) {
$response = $bc->call(gzcompress(json_encode($request))); // rpc queue
$response = $fakeResponse;
} else {
$response = $bc->call(gzcompress(json_encode($request))); // rpc queue
$response = json_decode(gzuncompress($response), true);
}
if (is_array($response) and $response[PAYLOAD_STATUS] != true) {
$msg = sprintf(ERROR_IPL_BROKER_PING, $brokerMap[$instance]);
consoleLog($res, CON_ERROR, $msg);
consoleLog($res, CON_ERROR, ERROR_IPL_STOP_BROKERS);
if (is_object($bc)) $bc->__destruct();
unset($bc);
exit(1);
} else {
consoleLog($res, CON_SUCCESS, sprintf(INFO_IPL_BROKER_SUCCESS, $brokerMap[$instance]));
}
if (is_object($bc)) $bc->__destruct();
unset($bc);
}
// if ($service == RESOURCE_BROKER and !empty($config[$service][CONFIG_BROKER_PRIME_INSTANCES])) {
// foreach (gasConfig::$settings[CONFIG_BROKER_SERVICES][$service][CONFIG_BROKER_PRIME_INSTANCES] as $primeService => $primeCount) {
// if ($primeCount and array_key_exists($primeService, $brokerMap)) {
// $bc = new gacBrokerClient($brokerMap[$primeService], basename(__METHOD__) . COLON_NS . __LINE__);
// if (!$bc->status) {
// $msg = ERROR_FAILED_TO_INSTANTIATE . $brokerMap[$primeService];
// consoleLog($res, CON_ERROR, $msg);
// consoleLog($res, CON_ERROR, ERROR_IPL_STOP_BROKERS);
// if (is_object($bc)) $bc->__destruct();
// unset($bc);
// exit(1);
// }
// }
// // publish the AMQP >PING< event request
// $response = $bc->call(gzcompress(json_encode($request))); // rpc queue
// $response = json_decode(gzuncompress($response), true);
// if ($response[PAYLOAD_STATUS] != true) {
// $msg = sprintf(ERROR_IPL_BROKER_PING, $broker[$primeService]);
// consoleLog($res, CON_ERROR, $msg);
// consoleLog($res, CON_ERROR, ERROR_IPL_STOP_BROKERS);
// if (is_object($bc)) $bc->__destruct();
// unset($bc);
// exit(1);
// } else {
// consoleLog($res, CON_SUCCESS, sprintf(INFO_IPL_BROKER_SUCCESS, $brokerMap[$primeService]));
// }
// if (is_object($bc)) $bc->__destruct();
// unset($bc);
// }
// }
}
}
}
// PEDIGREE Requests match the remote configurations to the local config (version number, release info, etc.)
// This ensures that all of the remote repos are on the same source-code branch...
// get the namaste (master) config (always required)
//$bc = new gacBrokerClient(BROKER_QUEUE_W, __METHOD__ . AT . __LINE__);
//if (!$bc->status) {
// $msg = ERROR_FAILED_TO_INSTANTIATE . BROKER_QUEUE_W;
// consoleLog($res, CON_ERROR, $msg);
// consoleLog($res, CON_ERROR, ERROR_IPL_STOP_BROKERS);
// if (is_object($bc)) $bc->__destruct();
// unset($bc);
// exit(1);
//} else {
// $response = $bc->call(gzcompress(json_encode($pedigreeRequest)));
// $response = json_decode(gzuncompress($response), true);
// $namastePedigree = $response[PAYLOAD_RESULTS];
// if (is_object($bc)) $bc->__destruct();
// unset($bc);
//}
//// get the admin config (always required)
//$bc = new gacBrokerClient(BROKER_QUEUE_AO, __METHOD__ . AT . __LINE__);
//if (!$bc->status) {
// $msg = ERROR_FAILED_TO_INSTANTIATE . BROKER_QUEUE_AO;
// consoleLog($res, CON_ERROR, $msg);
// consoleLog($res, CON_ERROR, ERROR_IPL_STOP_BROKERS);
// if (is_object($bc)) $bc->__destruct();
// unset($bc);
// exit(1);
//} else {
// $response = $bc->call(gzcompress(json_encode($pedigreeRequest)));
// $response = json_decode(gzuncompress($response), true);
// $adminPedigree = $response[PAYLOAD_RESULTS];
// if (is_object($bc)) $bc->__destruct();
// unset($bc);
//}
//
//// validate namaste config against the admin config
//if (serialize($adminPedigree) !== serialize($namastePedigree)) {
// $msg = sprintf(ERROR_IPL_CONFIG, ENV_APPSERVER, ENV_ADMIN);
// consoleLog($res, CON_ERROR, $msg);
// var_export($namastePedigree);
// consoleLog($res, CON_ERROR, ERROR_IPL_STOP_BROKERS);
// exit(1);
//}
//
//// if segundo is local, get and validate it's pedigree...
//if (isset($registeredServices[CONFIG_BROKER_SEGUNDO]) and intval($registeredServices[CONFIG_BROKER_SEGUNDO]) == 1) {
// $bc = new gacBrokerClient(BROKER_QUEUE_WH, __METHOD__ . AT . __LINE__);
// if (!$bc->status) {
// $msg = ERROR_FAILED_TO_INSTANTIATE . BROKER_QUEUE_WH;
// consoleLog($res, CON_ERROR, $msg);
// consoleLog($res, CON_ERROR, ERROR_IPL_STOP_BROKERS);
// if (is_object($bc)) $bc->__destruct();
// unset($bc);
// exit(1);
// } else {
// $response = $bc->call(gzcompress(json_encode($pedigreeRequest)));
// $response = json_decode(gzuncompress($response), true);
// $segundoPedigree = $response[PAYLOAD_RESULTS];
// if (is_object($bc)) $bc->__destruct();
// unset($bc);
// }
// if (serialize($namastePedigree) !== serialize($segundoPedigree)) {
// $msg = sprintf(ERROR_IPL_CONFIG, ENV_APPSERVER, ENV_SEGUNDO);
// consoleLog($res, CON_ERROR, $msg);
// var_export($namastePedigree);
// consoleLog($res, CON_ERROR, ERROR_IPL_STOP_BROKERS);
// exit(1);
// }
//}
//
//// if tercero is active, get and validate it's pedigree...
//if (isset($activeServices[CONFIG_BROKER_TERCERO]) and intval($activeServices[CONFIG_BROKER_TERCERO]) == 1) {
// $bc = new gacBrokerClient(BROKER_QUEUE_TBD, __METHOD__ . AT . __LINE__);
// if (!$bc->status) {
// $msg = ERROR_FAILED_TO_INSTANTIATE . BROKER_QUEUE_TBD;
// consoleLog($res, CON_ERROR, $msg);
// consoleLog($res, CON_ERROR, ERROR_IPL_STOP_BROKERS);
// if (is_object($bc)) $bc->__destruct();
// unset($bc);
// exit(1);
// } else {
// $response = $bc->call(gzcompress(json_encode($pedigreeRequest)));
// $response = json_decode(gzuncompress($response), true);
// $terceroPedigree = $response[PAYLOAD_RESULTS];
// if (is_object($bc)) $bc->__destruct();
// unset($bc);
// }
// if (serialize($namastePedigree) !== serialize($terceroPedigree)) {
// $msg = sprintf(ERROR_IPL_CONFIG, ENV_APPSERVER, ENV_TERCERO);
// consoleLog($res, CON_ERROR, $msg);
// var_export($namastePedigree);
// consoleLog($res, CON_ERROR, ERROR_IPL_STOP_BROKERS);
// exit(1);
// }
//}
consoleLog($res, CON_SUCCESS, SUCCESS_IPL_ENV_CHECK);
if (intval(gasConfig::$settings[CONFIG_BROKER_APPSERVER][CONFIG_ACTIVE]) == 1) {
consoleLog($res, CON_SUCCESS, INFO_IPL_APPSERVER_SUCCESS);
}
if (intval(gasConfig::$settings[CONFIG_BROKER_SEGUNDO][CONFIG_ACTIVE]) == 1) {
consoleLog($res, CON_SUCCESS, INFO_IPL_SEGUNDO_SUCCESS);
}
if (isset(gasConfig::$settings[CONFIG_BROKER_TERCERO][CONFIG_ACTIVE]) and intval(gasConfig::$settings[CONFIG_BROKER_TERCERO][CONFIG_ACTIVE]) == 1) {
consoleLog($res, CON_SUCCESS, INFO_IPL_TERCERO_SUCCESS);
}
if (intval(gasConfig::$settings[CONFIG_ADMIN][CONFIG_ACTIVE]) == 1) {
consoleLog($res, CON_SUCCESS, INFO_IPL_ADMIN_SUCCESS);
}

24
scripts/stopBrokers.sh Normal file
View File

@@ -0,0 +1,24 @@
#!/usr/bin/env bash
#
# brokerStop.sh
#
# quick and dirty shell script to stop broker processes by sending the TERM kill signal.
# Brutal yet effective.
#
# HISTORY:
# --------
# 06-15-17 mks original coding
#
SCRIPT=$(readlink -f $0)
SCRIPTPATH=$(dirname ${SCRIPT})
PIDDIR="/../pids/"
PDIR=${SCRIPTPATH}${PIDDIR}
for pid in `ps -ef | awk '/\/brokers\// && !/awk/ {print $2}'`
do
kill $pid
done
rm ${PDIR}/* 2>/dev/null