SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Aug 2005
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting a resource id

    Just wondering if anyone knows a clean way of getting a resource id from any type of resource, like ( $result = pg_query (), where the $result -> id = #44) or other. Basically I want to track unlimited resources so I can provide detailed reporting (times resource was passed back to class, functions called by the resource, execution time [per action], idle time) through the life of each resource. I haven't seen any class that does this as there seems to be no clean way to get the resource id. Yes I know I could just pass out each resource via an $object->resource[2], but that will just over complicate the usage!

    tia!

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Addict
    Join Date
    Aug 2005
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    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] ) > )
            {
                
    $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 );

                
    $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 );

    $obj_1 $worker->exampleOne $obj_1 );

    sleep );

    $obj_2 $worker->exampleOne $obj_2 );

    sleep );

    $obj_1 $worker->exampleOne $obj_1 );

    print_r $worker->info );
        
    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •