PHP Classes

PHP Script Profiler: Profile the execution of PHP scripts

Recommend this page to a friend!
  Info   View files Example   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 138 This week: 1All time: 9,231 This week: 560Up
Version License PHP version Categories
script_profiler 1.0.0Custom (specified...5.4PHP 5, Time and Date, Performance and...
Description 

Author

This class can profile the execution of PHP scripts.

It can start measuring the time a section of a script takes to execute from one point to another point of the script.

Each profiled section may have a named label. Multiple sections can be profiled in the same script.

A summary of the profiled script sections can be displayed outputted to a given log file. It includes the time spent and the memory being used.

Picture of Mike Jordan
  Performance   Level  
Name: Mike Jordan <contact>
Classes: 5 packages by
Country: United States United States
Age: 61
All time rank: 1460219 in United States United States
Week rank: 416 Up46 in United States United States Up
Innovation award
Innovation award
Nominee: 1x

Example

<?php

require_once 'PHP Profiler/profiler.php';
$profile = new profiler;

$point_1 = $profile->start_profile( 'Script Includes' );

include
'objSQL_3.5.2/objSQL.php';

$profile->stop_profile( $point_1 );

$point_2 = $profile->start_profile( 'DB Connection' );

$dbh = new objsql( array( 'sqlite', '', '', '', 'G:\www\dev\Projects\mojotest2.sq3' ) );

if (
error_get_last() !== null )
    throw new
Exception( error_get_last()['message'] );
else
    echo
"objSQL Version: {$dbh->obj_info()['OBJSQL_VERSION']}<br />
          Database:
{$dbh->obj_info()['DATABASE_NAME']}<br />
          Driver:
{$dbh->obj_info()['DATABASE_DRIVER']}<br />
          DB Type:
{$dbh->obj_info()['DATABASE_TYPE']}<br />
          Version:
{$dbh->obj_info()['DATABASE_VERSION']}<br />
          Collation:
{$dbh->obj_info()['DATABASE_CHARSET']}<br />
          PHP Version:
{$dbh->obj_info()['PHP_VERSION']}<br /><hr />";
               
$profile->stop_profile( $point_2 );

$point_3 = $profile->start_profile( 'Insert Query' );
       
for (
$i = 1; $i < 41; $i++ )
{
   
$data = array( 'f_name' => 'Bob',
                  
'l_name' => 'Jones' );
   
   
$rs = $dbh->obj_insert( 'emp_test', $data );
               
    if (
$dbh->obj_error() )
        throw new
Exception( $dbh->obj_error_message() );
               
   
$data = array( 'f_name' => 'Helen',
                  
'l_name' => 'Xavier' );
   
   
$rs = $dbh->obj_insert( 'emp_test', $data );
               
    if (
$dbh->obj_error() )
        throw new
Exception( $dbh->obj_error_message() );
   
   
$data = array( 'f_name' => 'Ken',
                  
'l_name' => 'Gomez' );
   
   
$rs = $dbh->obj_insert( 'emp_test', $data );
               
    if (
$dbh->obj_error() )
        throw new
Exception( $dbh->obj_error_message() );
   
   
$data = array( 'f_name' => 'Patty',
                  
'l_name' => 'Cline' );
   
   
$rs = $dbh->obj_insert( 'emp_test', $data );
               
    if (
$dbh->obj_error() )
        throw new
Exception( $dbh->obj_error_message() );
}

$profile->stop_profile( $point_3 );

$point_4 = $profile->start_profile( 'Select Query' );

$rs = $dbh->obj_select( 'emp_test', '', 'emp_id' );
       
if (
$dbh->obj_error() )
    throw new
Exception( $dbh->obj_error_message() );
       
while (
$rs->obj_fetch_assoc() )
{
    echo
"{$rs->obj_field( 'emp_id' )} -
         
{$rs->obj_field( 'f_name' )} -
         
{$rs->obj_field( 'l_name' )}<br />";
}
       
$rs->obj_free_result();
       
$profile->stop_profile( $point_4 );

//save to log file
$profile->print_profile( 'profile_log.txt' );

//print to screen
echo "<pre>{$profile->print_profile()}</pre>";

?>


Details

App: PHP Script Profiler Version: 1.0.0 Author: MT Jordan <mtjo62@gmail.com> Copyright: 2014 License: zlib/libpng License ********************************************************************************** PHP Script Profiler is a script profiler that is designed to help determine execution time or memory bottlenecks in PHP scripts. ********************************************************************************* PHP Script Profiler Features: * Diagnose execution time errors or memory errors for intensive SQL queries * List unnecessary or unknown included/required files * Create unlimited profile points * Print to screen or save to local file Requirements: * PHP 5.4+ ********************************************************************************* Usage: <?php include 'profiler.php'; $profile = new profiler; //Create profile point $point_1 = $profile->start_profile( 'Profile Description 1' ); //Code to profile - ie: SQL Query, display data, etc. //End profile point $profile->stop_profile( $point_1 ); //Create profile point $point_2 = $profile->start_profile( 'Profile Description 2' ); //Code to profile - ie: SQL Query, display data, etc. //End profile point $profile->stop_profile( $point_2 ); //Print to screen echo "<pre>{$profile->print_profile()}</pre>"; //Write to file $profile->print_profile( 'logs/profile_log.txt' ); ?>

  Files folder image Files  
File Role Description
Accessible without login Plain text file example.php Example Example script
Accessible without login Plain text file license.txt Lic. License File
Plain text file profiler.php Class PHP Script Profiler is a script profiler
Accessible without login Plain text file profile_log.txt Output Example log file
Accessible without login Plain text file readme.txt Doc. Readme file

 Version Control Unique User Downloads Download Rankings  
 0%
Total:138
This week:1
All time:9,231
This week:560Up