
Originally Posted by
logic_earth
Thanks for that but those will not help. I'm trying to make a debugging test class that can keep track of all objects / resources so as to monitor what exactly each object / resource is doing along with the timing of all their actions through the scripts lifetime. So what I am really trying to do is ELIMINATE the need for CALLING ob_() to get the object / resource id which is needed to keep an organized tracking record of each object / resource.
A simple example...
PHP Code:
<?php
class worker
{
/**
* class self, instance
*
* @var object
**/
private static $instance;
/**
* class self
*
* holds information about each object
*
* @var array
*/
public $info = array ();
/**
* class self
*
* holds the object id
*
* @var integer
*/
private $id = 0;
/**
* class self
*
* holds all object or resource handles currently open
*
* @var array
*/
private $open = array ();
/**
* class community_one constructor
**/
private function __construct ()
{
}
/**
* instance of class self
**/
public static function getInstance ()
{
return ! self::$instance ? new worker () : self::$instance;
}
/**
* create a new object and return it
**/
public function newObject ()
{
$obj = new stdClass();
$this->open[$this->get_id ( $obj )] = array ( 'time' => microtime ( true ) );
$this->update_time ( 'New Standard Object Total Execution Time' );
return $obj;
}
/**
* update the object tracking time
*/
private function update_time ( $type )
{
$time = microtime ( true ) - $this->open[$this->id]['time'];
$this->info[$this->id][] = array ( 'time' => $time, 'type' => $type );
if ( count ( $this->info[$this->id] ) > 1 )
{
$this->info[$this->id][0]['time'] += $time;
}
$this->open[$this->id]['time'] = microtime ( true );
return;
}
/**
* ob get resource or object id
*/
// want to ELIMINATE this, (find a cleaner way to get the #id)
private function get_id ( $result )
{
ob_start ();
var_dump ( $result );
$t = ob_get_contents ();
ob_end_clean ();
$this->id = 'R' . @substr ( ( $t = @substr ( $t, @strpos ( $t, '#' ) ) ), 0, @strpos ( $t, ' ' ) );
return $this->id;
}
/**
* example worker function
**/
public function exampleOne ( $obj )
{
if ( isset ( $this->open[$this->get_id ( $obj )] ) )
{
$this->update_time ( 'Object Idle Time' );
sleep ( 1 );
$obj->counter = 1;
$this->update_time ( 'Function (exampleOne) Execution Time' );
return $obj;
}
/* trigger_error (); */
die ( 'not a object created by class worker::newObject' );
}
}
$worker = worker::getInstance();
$obj_1 = $worker->newObject ();
$obj_2 = $worker->newObject ();
sleep ( 1 );
$obj_1 = $worker->exampleOne ( $obj_1 );
sleep ( 1 );
$obj_2 = $worker->exampleOne ( $obj_2 );
sleep ( 1 );
$obj_1 = $worker->exampleOne ( $obj_1 );
print_r ( $worker->info );
?>
Bookmarks