Jump to content

Documentation on Hooks?


nexflo
 Share

Recommended Posts

Right now just want to setup a very simple logger, which tells me the time taken for the page to render and how much memory was used.

I setup a super ultra light module as follows:

    public function init() {
    $this->addHookBefore('Page::render', $this, 'timeStart'); 
        $this->addHookAfter('Page::render', $this, 'getStat'); 
 
    }
 
 
    public function timeStart(){
        $this->$timestart = microtime(true);
    }
 
    public function timeNow(){
        return microtime(true)-$this->$timestart;
    }
 
    public  function convert($size) {
        $unit=array('b','kb','mb','gb','tb','pb');
        return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
    }
    
    public function getMemory(){
        return $this->convert(memory_get_peak_usage(true));
    }
 
    public function getStat(){
        echo '<!-- Page generated in '.$this->timeNow().' secs, Memory Usage: '.$this->getMemory().' -->';
    }
 
 
issue is: i want to hook into the very first and very last instance of processwire..i cant really seem to find the right hooks, or a documentation about it?
 
cheers
Link to comment
Share on other sites

Look for my ChromePhp debug module.

If you want from start to end of full pw youd have to insert your code in top and bottom index.php gateway. No way to hook that obviously.

Link to comment
Share on other sites

While Soma is right that the only way to get 100% before and after everything that happens is to literally put it in index.php, there are a couple of hooks that may provide what you need. An autoload module's init() function is a good starting point, and ProcessPageView::finished is a good hook to end with. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...