www.KevinBurkholder.com

Getting Work Done Through People

Getting People Done Through Work

www.KevinBurkholder.com
Strengths Based Performance Management
EarthAsylum Consulting
The EarthAsylum Leadership Circle
The EarthAsylum Fusion Network
Tuesday, November 25, 2008

Web Developer Tools

PostTest.php - Form testing utility
eac_timer.class.php - Track and report execution timing
nocaching.inc - Prevent browser caching

PostTest.php

Source Code

Download PostTest.zip

Live Example

Interested in using this software in your project? Contact Kevin at KBurkholder@EarthAsylum.com
Creative Commons License This work is licensed under the Creative Commons GNU-LGPL License.
Licensing & Registration
 
Donations are greatly appreciated and help fund further development and maintain the LGPL licensing.

PostTest Overview

PostTest.php is a simple PHP utility that displays important information about a form post that can be useful when testing new forms or cross-site form posts.

PostTest.php generates a formatted display of all POST fields, GET fields, Request Headers, and Response Headers.

 

Usage Summary

When creating and testing a new form, assign "PostTest.php" as your form's action:

<form action='PostTest.php' method='post' name='FormName'

To use within an existing form action program and to have the test page emailed to you, define the "POST_TEST_OUTPUT" constant with your e-mail address and include "PostTest.php". If your form action sets any response headers, it would be best to include PostTest.php at the end of the program.

define(POST_TEST_OUTPUT,'you@doamin.com');
include(
'PostTest.php'); 

If you're testing a simple href link or form post using the GET method, you can define the e-mail address using the "_pto=" query variable or hidden field.

<a href='PostTest.php?_pto=you@domain.com' OR <form action='PostTest.php' method='get' name='FormName'>
    <
input type='hidden' name='_pto' value='you@domain.com' /> 

eac_timer.class.php

Source Code

Download eac_timer.class.zip

Interested in using this software in your project? Contact Kevin at KBurkholder@EarthAsylum.com
Creative Commons License This work is licensed under the Creative Commons GNU-LGPL License.
Licensing & Registration
 
Donations are greatly appreciated and help fund further development and maintain the LGPL licensing.

eac_timer.class Overview

eac_timer.class.php is a testing module used to record and evaluate the PHP execution time of a page, module, or function. It tracks the total execution time from when it is loaded to the completion of the PHP process as well as events set within individual programs.

eac_timer.class.php starts a timer when the class is instantiated through the __constructor method and ends the timer when PHP execution halts via the __destructor method. Other timers can be added by the developer at any point and in any program or include file using the methods listed below.

Usage Summary

include('eac_timer.class.php');
$timer = new Timer(output);       // the output for the global timer
$timer->output 'xxx[,xxx]';     // notice,print,email,session,header
$timer->format '[Timer %0d] %s at %s; Elapsed Time: %01.4f seconds.';
$timer->sendTo 'email_address'// override the default email address
$timer->start(id);                // start a timer, id=name of timer
$timer->pause(id);                // pause a timer
$timer->unpause(id);              // unpause a timer
$timer->stop(id);                 // stop a timer
// get elapsed time. (via=notice/print/email/session/header or null)
$var $timer->get(id,via);
 

The "id" parameter can be any name you like to give to your timer but it must be unique among all of your set timers. The __constructor method always starts a timer that uses $_SERVER["PHP_SELF"] as the id.

The "output" parameter [$timer = new Timer(output), $timer->output =, and $timer->get(id,output)] can be any one or combination of: "notice", "print", "email", "session" or "header". If multiple output formats are used, separate them with a comma.

The "output" parameter of the instantiation call [$timer = new Timer(output)] is used only to set the output for the global timer when the destructor method is called. When "output" is (or contains) "email", all timers are reported and sent in one email message.

When "header" is used, an http response header named "X-EAC-Timer-z (z = the relative index number of the timer) with the timer message as specified by the "format" option. If headers have already been sent, this option is ignored.

When "print" is used, an html comment (<!-- ... -->) is generated with the output message. The comment is only generated if the headers have already been sent or if output buffering is on. This prevents html output from being generated before all headers have been sent.

When "notice" is used, a "trigger_error" is raised with an error level of "E_USER_NOTICE". This can be used by a custom error routine to capture the notice.

When "email" is used, an email message is sent to the address specified in the $timer->sendTo variable.

When "session" is used, the output message is stored in $_SESSION["Timer"][id].

When eac_timer.class.php creates the output message, it uses "sprintf" with 4 parameters. 1) the relative index number of the timer, 2) the ID of the timer, 3) the date/and time (date('r')), and 4) the elapsed time in microseconds. The message can be set by setting the value of $timer->format.

When an email message is sent, the default address is either the value of $_SERVER["SERVER_ADMIN"] or webmaster@$_SERVER["HTTP_HOST"]. This can be changed to any email address by setting the value of $timer->sendTo.

Example:


include("eac_timer.class.php");
// start a timer using $_SERVER['PHP_SELF'] as the id
// and set the output to 'email'.
$timer = new Timer('email');
// set the default output for all timers to 'notice'.
$timer->output 'notice';
... 
your code ...
function 
afunction() {
    global 
$timer;
    
$timer->start('afunction'); // time this function
    
... your code ...
    
// get the elapsed time and print an html comment
    
$timer->get('afunction','print');
}
// the __destructor method will send an email 
// with the elapsed time of this script
 


nocaching.inc

Source Code

Download nocaching.zip

Interested in using this software in your project? Contact Kevin at KBurkholder@EarthAsylum.com
Creative Commons License This work is licensed under the Creative Commons GNU-LGPL License.
Licensing & Registration
 
Donations are greatly appreciated and help fund further development and maintain the LGPL licensing.

nocaching Overview

Doesn't get any simpler than this. Add this to your PHP pages to prevent browsers from caching the page.

include "nocaching.inc"

 

A better alternative may be found here
» PHP Caching/Compression



 Powered by  eac::Framework 

eac::Framework is a lightweight PHP & JavaScript framework for Web 2.0 Applications and E-Commerce systems.

For more information, visit http://www.KevinBurkholder.com/framework

eac::encryption, eac::session, eac::keychain, eac::dataobjects, eac::tracker, eac::sourcing, eac::authentication, eac::filter, eac::formgen, eac::caching, eac::mailer, eac::download, eac::error, eac::streams and more.