This tutorial details the integration of Zend Platform’s Event Details screens with other legacy applications.
Reproducing and resolving bugs, one of the most problematic challenges of development, is often time consuming, and in most cases, almost impossible when information is not collected at the time of the occurrence. PHP Intelligence is an event driven system that provides real-time analysis of PHP applications.
By enabling you to obtain immediate insight into your PHP applications, PHP Intelligence provides a fast and efficient means to reproduce and resolve problems, while maintaining a complete audit trail of the occurrence's details.
PHP Intelligence pro-actively alerts you to problematic occurrences in your application. This means that if you are a Developer or System Administrator you will not need to monitor the Platform console at all times-instead, the information comes to you! An event, containing the audit trail of an occurrence, can be made known to you through an E-mail Notification. If you require full event details available outside of the Platform console, an Event Details screen can be published to a URL in XML format. Both Event Details screens contain aggregated information relevant to the occurrence of an event, or in other words "Full Problem Context": Event type, Event ID, Timestamp, Severity, number of occurrences, etc.
Full Problem Context provides valuable information for the entire PHP application lifecycle (development, production and deployment). Exposing the source of an occurrence along with the ability to drill-down and investigate details pertaining to an event’s location, time and context, provides in-depth insight to the reasons why the event occurred and a basis for resolving the issue.
PHP Intelligence includes the following Event Details screen Types: Slow Script Execution, PHP Errors, Function Errors, Memory Usage, Database Errors, Query Execution, Output Sizes, Load Averages and more...
Each Event Details screen Type includes basic and event-specific details such as: event type, event ID, Timestamp, Severity, number of occurrences, error type, error text, triggered value, load average, Source File Line, Script Name, Host URI, Vardata Type & Name, Function Name, Argument Numeric Value, Function, Included Files, Backtrace, etc.
Contents of the XML output can be easily utilized and integrated to provide an information feed to various legacy systems such as: Bug tracking systems for development and QA, CRM applications for managing customer care, management systems such as Tivoli and HP OpenView for system health information, and most commonly, generic monitoring systems such as Nagion or BigBrother that only provide OS service information.
Using event information, developers and administrator teams have a single point of reference to streamline the maintenance workflow. You can further enhance your development lifecycle by debugging your PHP code referenced in Event Details screens directly through the built-in integration with Studio. This feature includes debug capabilities that enable you to add watches, define conditional breakpoints, view the stack trace and step into the source code to immediately debug the problem.
Platform's XML output enables information to be easily interchanged. Using "Event Details", developers can be sure that information pertaining to code, database and performance issues can be easily reused in a multitude of applications. Examples of this use include sending SMS messages containing event details, or triggering a mailing system to send a promotional gift to a customer who encountered a performance problem. Done by, extracting customer ID information provided to you in the Event Details screen (cookies).
Event Details screens are delivered as XML, by defining the relevant action ("Submit Report to the Specified URL") for an event. The report information is submitted as XML data to the specified URL. Submission is done using the POST method, and the data is supplied through a variable named 'event_data'. This variable is accessible in PHP through $_POST['event_data'].
XML reports are structured as follows:
Each attribute is included if it exists in the Event Details screen:
<?xml version="1.0" ?>
<event type event_id class timestamp time severity>
If there is an error:
<error type>error text</error>
<stats triggered_value avg load_average/>
If there is a source file:
<source file line/>
<script name host uri>
<vardata type name value/>
</script>
If there is a function:
<function name>
<args>
<arg num value/>
</args>
</function>
If there are included files:
<included_files>
<file name\>
</included_files>
If there is a backtrace for this event:
<backtrace>
<call depth function file line/>
</backtrace>
</event>
By viewing the XML tagged file as fielded text, the fielding makes it possible to break Event Details screens down to their component parts to any degree of granularity for storage in a database. Once in the database, the data can be utilized by another application.
The following example shows how Event Details data can be extracted from an XML file and inserted into a database for use in a different system (could be any system based on a database, such as: Bug Tracking, CRM, management or any other application).
<?PHP
$event_xml_data = (isset($_POST['event_data']))?$_POST['event_data']:null;
if (!$event_xml_data) { // no Event Context arrvied
die();
}
$xml = simplexml_load_string($event_xml_data);
Implement different behaviors according to Class
$event_type = (string) $xml['type'];
// if this event is a Custom Event, we may implement different behaviors according to the Custom Event’s class
if ($event_type == 'custom') {
$custom_class = (string) $xml['class'];
switch ($custom_class) {
// different behaviors according to the class
}
}
// get the new event id
$event_id = (int) $xml['event_id'];
// insert a new event with its genreal info (type and timestamp) to the db
insert_new_event_into_db($event_id,$event_type ,(int)
$xml['timestamp']);
// parse the function parameters of the function where the event occured
$function_parameters = array();
foreach ($xml->function->args->arg as $arg) {
$function_parameters[(int) $arg['num']] = (string) $arg['value'];
}
// insert the function data (function name and parameters, where the
event occured) to the db
update_event_function_data($event_id, (string) $xml->function['name'],
$function_parameters);
/**
* insert a new event (with some genreal info) to the db
*
* @param int $id id of the new event in the ZendPlatform events database
* @param string $type the event type
* @param int $timestamp the unix timestamp when the event occured
*/
function insert_new_event_into_db($id,$type,$timestamp) {
}
/**
* update a specific event function data in the database
*
* @param int $id the event id we want to update
* @param string $function_name name of the function where the event occured
* @param array $function_params array of the function parameters (num
=> value)
*/
function update_event_function_data($id,$function_name,$function_params) {
}
?>
The first part of the example uses a PHP 5 Simple XML extension to parse XML to PHP objects that can be processed with normal property selectors and array iterators. The second part extracted data from the event XML data, and inserted it into a database.
|
As this tutorial demonstrated, XML Event Details generated by the PHP Intelligence component, provides Developers and System Administrations a single point of reference for production environments, and to streamline maintenance workflow. In environments where multiple management applications are an everyday reality, Platform provides a flexible information feed to legacy systems, relieving the overhead normally required to integrate with these applications. |