Yii 1.1: phpquickprofiler

Particletree.com Php Quick Profiler Wrapper
39 followers

Particletree.com Php Quick Profiler Wrapper

Its a Web Log Router that will help you profile your application, its database profiling feature allows you to quickly find duplicated queries, see which queries are taking too long, the memory tab allows you to find memory leaks, and it also looks beautiful!

Requirements

Developed using Yii Framework 1.1.8 but it may work with other versions.

Usage

  • Download and extract the contents of the zip to your extensions folder
  • Configure the LogRoute in your application configuration
'log'=>array(
            'class'=>'CLogRouter',
            'routes'=>array(
                array(
                    'class'=>'CFileLogRoute',
                    'levels'=>'error, warning',
                ),
                array(
                    'class' => 'application.extensions.pqp.PQPLogRoute',
                    'categories' => 'application.*, exception.*',
                ),
            ),
        ),

Note: if you plan to use phpunit and for some reason you are using a config file that includes PQP you'll get errors about assets folder, to solve this you can set up you log route in the following way as suggested by thefsb

'log'=>array(
            'class'=>'CLogRouter',
            'routes' => array_merge(
        array(
            array(
                'class'=>'CFileLogRoute',
                'levels'=>'error, warning, info',
            ),
        ),
        array(php_sapi_name() !== 'cli'
            ? array(
                'class' => 'application.extensions.pqp.PQPLogRoute',
                'categories' => 'application.*, exception.*, system.*',
                'levels'=>'error, warning, info',
            )
            : array('class'=>'CWebLogRoute', 'enabled'=>false)
        )
    ),
        ),
  • Enable Database Profiling and param loggin:
'db'=>array(
            'connectionString' => '...',
            'enableProfiling' => true,
            'enableParamLogging' => true,
        ),
  • Log as you normaly would with Yii using Yii::trace, Yii::log, Yii::beginProfile and Yii::endProfile, use PQPLogRoute::logMemory to log memory, you can use it to log objects to know its memory consumption, if you pass a string it will tell you know much memory has been used to that point.
/**
     * Logs a memory message.
     * @param mixed $obj any type of variable to profile memory
     * @param string $msg message to be logged
     * @param string  $category category of the message (e.g. 'system.web'). It is case-insensitive.
     */
    public static function logMemory($obj, $msg = '', $category='application'){
PQPLogRoute::logMemory("memory used after action call");
try {
    Yii::beginProfile('Execution time');
    Yii::log('Begin logging data');
    PQPLogRoute::logMemory($this, "the site controller");
    $arr = array('Name' => 'Ryan', 'Last' => 'Campbell');
    Yii::log(CVarDumper::dumpAsString($arr));
    PQPLogRoute::logMemory($arr, "Normal array");
    $users = User::model()->findAll();
    PQPLogRoute::logMemory($users, "Users array");
    Yii::endProfile('Execution time');
    throw new Exception('Unable to write to log!');
}
catch(Exception $e) {
    Yii::log($e, CLogger::LEVEL_ERROR);
}
PQPLogRoute::logMemory("memory used before render");

Resources

  • Project page
  • Demo: in the downloads
  • Forum Post your questions there, avoid posting questions in the extension page.
  • Screenshots : ConsoleSpeedDatabaseMemoryFiles

Total 11 comments

#7936 report it
Mohammad Shahid at 2012/04/27 05:45am
About Persistence Logging

Is there any way to keep log history on each refresh?

Suppose we have a submit form and when we submit the form it sends the values a action file and page is suddenly redirected to success page. So your logging system logs of success page but not of the action page. If we want to show the form value in log while processing the action before redirecting the success page then how we can do this?

We can achieve this in file logging because all logged data are appended every time logger is called.

If you implement the history system then your extension will be best among all.

thanks for providing a great extension.

#7935 report it
Mohammad Shahid at 2012/04/27 05:29am
Enable/Disable Extension Automatically

Thanks for providing a very useful extension.

Is there any easy way to enable the extension only on 127.0.0.1(localhost) and disable automatically if it is not on localhost.

#5969 report it
webscriptz.be at 2011/12/01 10:39am
Idea

IT's great now that i got it to work correctly!

Maybe we could adapt it to be the default profiler and log utility for the whole application.

#5948 report it
fsb at 2011/11/28 07:56am
the screenshots are on this page

@oceatoon the screenshots are right above these comments

#5939 report it
Asgaroth at 2011/11/27 01:17pm
@webscriptz

Please check this post

Please try to keep your questions in the forum.

#5933 report it
webscriptz.be at 2011/11/27 05:06am
unfortunately

It really is a nice piece of software but unfortunately i can't seem to get it to work properly, i've even copied it from the svn on google code and it still doesn't show anything...

#5874 report it
Raoul at 2011/11/21 04:59pm
super

reading yii log has never been that easy !!! thanks for this great extension ....

#5869 report it
fsb at 2011/11/21 11:58am
Lovely. Works like a charm

This is a nice improvement over the built in profiling and web logger.

And it looks impressive too.

#5867 report it
Asgaroth at 2011/11/21 09:17am
@oceatoon

Hi,

Its a Web log route, meaning it will show up in every page, if you are not seeing anything, try to log something, or add system.* to your categories.

#5865 report it
yiqing95 at 2011/11/21 08:44am
great extension ! looks nice

thanks for sharing , the class is worth reading , good skills

#5859 report it
Tibor Katelbach at 2011/11/21 01:38am
what url to see the log as in screenshots ?

Hi sounds interesting but what's the url to see the log as in screenshots ?

Leave a comment

Please to leave your comment.

Create extension