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

View File

@@ -0,0 +1,149 @@
/**
* getNoSQLResource() -- private static method
*
* this method initializes the nosql resource by attempting to connect to the nosql service. if the connection
* attempt succeeds, then mark the resource as available. Otherwise, post an error-fatal and explicitly mark
* the service as not-available and return.
*
* NOTE:
* -----
* This resource allocation exists outside of the resource manager because the resource manager instantiates
* this class in it's constructor. Were you to request a resource from the resource manager, you'd end-up in
* a circular reference and if the whole thing does not come to an immediate shuddering stop, then it would
* certainly blow-up the first time you attempt to log an error. So, tl;dr: do not attempt to 'fix' this as
* it's not broken.
*
* @author mike@givingassistant.org
* @version 1.0
*
* @return Aws\DynamoDb\DynamoDbClient|null
*
* HISTORY:
* ========
* 06-09-17 mks original coding
*
*/
private function getNoSQLResource():Aws\DynamoDb\DynamoDbClient
{
global $eos;
$options = null;
date_default_timezone_set(TIME_TIMEZONE);
if (empty($this->config)) {
echo getDateTime() . CON_ERROR . $this->res . ERROR_CONFIG_RESOURCE_404 . CONFIG_DATABASE_DDB . $eos;
return(null);
}
$noSQLConfig = $this->config[CONFIG_DATABASE_DDB_APPSERVER];
$credentials = [
STRING_KEY => $noSQLConfig[CONFIG_DATABASE_DDB_APPSERVER_KEY_ID],
STRING_SECRET => $noSQLConfig[CONFIG_DATABASE_DDB_APPSERVER_ACCESS_KEY]
];
/*
* Requests to DynamoDB are made over HTTP(S), and this does not require that you establish an upfront
* connection. When you create the client object, you are not making a connection to DynamoDB, you are just
* configuring an HTTP client that will make requests to DynamoDB.
*/
$awsConfig = new Aws\Sdk([
STRING_ENDPOINT => $noSQLConfig[CONFIG_DATABASE_DDB_APPSERVER_DSN] . ':' . $noSQLConfig[CONFIG_DATABASE_DDB_APPSERVER_PORT],
STRING_REGION => $noSQLConfig[CONFIG_DATABASE_DDB_APPSERVER_REGION],
STRING_VERSION => $noSQLConfig[CONFIG_DATABASE_DDB_APPSERVER_VERSION],
STRING_CREDS => $credentials
]);
return $awsConfig->createDynamoDb();
}
/**
* getLog() - public method
*
* getLog is the method that is used to fetch log (or Metrics) records from the mongo collection.
*
* because ddb limits queries to 1MB returns, and the paint is still wet on this schema, for now I'm
* going to limit queries for log-file fetching to just the last N records created within the last hour and
* we'll just grab up to the limit of the records returned - which should still be a significant number of
* records...
*
* This method reads the last X records created in the last hour (since this method is mainly used for
* providing HTML output to the log-reader) and wraps the data in HTML table rows intended for the logDump
* utility.
*
* todo -- pagination support? Query by error-code? Query by eventID? Query by class?
*
* @author mshallop@pathway.com
* @version 1.0
*
* @param string $_what defaults to the log template -- should be over-ridden for metrics template
* @return null|string
* @throws Exception
*
* HISTORY:
* ========
* 06-07-17 mks original coding
* 06-14-17 mks refactored for ddb
*
*/
public function getLog(string $_what = TEMPLATE_CLASS_LOGS):string
{
$result = null;
$returnData = null;
$marshaler = new Marshaler(); // black-box son converter
$lastHour = time() - NUMBER_ONE_HOUR_SEC;
if ($_what != TEMPLATE_CLASS_LOGS and $_what != TEMPLATE_CLASS_METRICS) $_what = TEMPLATE_CLASS_LOGS;
$eav = $marshaler->marshalJson('{":ts" :' . $lastHour . '}');
$params = [
DDB_STRING_TABLE_NAME => $this->collectionName,
DDB_STRING_KEY_COND_EXPR => LOG_CREATED . ' > :ts',
DDB_STRING_EXPR_ATTR_VALS => $eav
];
try {
$result = $this->connection->query($params);
} catch (DynamoDbException $e) {
$this->errStack[] = __FILE__ . ':' . __LINE__ . ':' . __METHOD__ . ':' . $this->class . ':' .
ERROR_FATAL . ' caught cursor exception: ' . $e->getMessage();
self::throwFatal();
}
if (!is_null($result)) {
foreach ($result[DDB_STRING_ITEMS] as $row) {
$returnData .= '<div class="rowMeta">'; // note: css is defined in the utilities directory
$returnData .= '(' . $row[(DB_PKEY . $this->ext)] . ') - ';
// $returnData .= date(TIME_DATE_FORMAT, $row[(META_SESSION_DATE . self::$ext)]->sec) . ' - ';
// add error label as a span: warn/error/fatal...
$returnData .= self::getErrorLabel($row[(LOG_LEVEL . $this->ext)]);
$returnData .= ' ' . $row[(ERROR_FILE . $this->ext)] . '(' . $row[(ERROR_LINE . $this->ext)] . ')';
$cd = '';
if (!empty($row[(ERROR_CLASS . $this->ext)])) $cd = ' class[' . $row[(ERROR_CLASS . $this->ext)] . ']';
if (!empty($row[(ERROR_METHOD . $this->ext)])) $cd .= '.method(' . $row[(ERROR_METHOD . $this->ext)] . ')</div>';
$returnData .= $cd;
/*
if ($row[(ERROR_TYPE . self::$ext)] == ERROR_TRACE) {
$returnData .= '</div>';
}
*/
$returnData .= '<div class="rowData">' . htmlentities($row[(ERROR_MESSAGE . $this->ext)]);
if ($_what == TEMPLATE_CLASS_METRICS) {
$returnData .= ' - ' . $row[(DB_TIMER . $this->ext)] . ' or ';
$returnData .= ($row[(DB_TIMER . $this->ext)] * NUMBER_MS_PER_SEC) . 'ms';
}
$returnData .= '</div>';
$returnData .= '<div class="rowHist">';
foreach($row[(DB_HISTORY . $this->ext)] as $histRec) {
$returnData .= date('Y-M-d h:i:s', $histRec[META_SESSION_DATE]->sec);// . ' (';
if (!is_null($row[(LOG_EVENT_GUID . $this->ext)]))
$returnData .= ', Event ID: ' . $row[(LOG_EVENT_GUID . $this->ext)];
// $returnData .= $histRec[META_SESSION_EVENT] . ') from (';
// $returnData .= $histRec[META_SESSION_IP] . '): ';
// $returnData .= ((isset($histRec[META_SESSION_ID])) ? $histRec[META_SESSION_ID] : $histRec[META_CLIENT]) . '<br />';
}
$returnData .= '</div><br />';
}
}
return ($returnData);
}