Download the PHP package particletree/pqp without Composer
On this page you can find all versions of the php package particletree/pqp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download particletree/pqp
More information about particletree/pqp
Files in particletree/pqp
Package pqp
Short Description Simple PHP profiler to track application behavior during development
License MIT
Informations about the package pqp
PHP Quick Profiler
PHP Quick Profiler is a simple profiler to track application behavior during development.
Installation
It's recommended that you use Composer to install PHP Quick Profiler.
This will install PHP Quick Profiler. It requires PHP 5.3.0 or newer.
Usage
The basic profiler only needs a few dedicated lines of code to get up and running. If you want to add in query analysis you'll need to track queries independently and inject them before render.
For the basic profiler:
This will spit out some styled html that sits on the footer of your page with a few messages. The html will only be displayed if Profiler::display()
is called, so if you want to hide the data (like, in a production environment) then just wrap that call in a check.
Console
The Console class is a basic holder of logged information. The best way to handle it is to create a new instance and stuff it in a container/service locator and then pass things in throughout your application. Worst case you can throw it in the $_GLOBALS array, but I didn't say that.
Note: the original Particletree release had this class as a psuedo-static singleton. This version does not do that. The Console class follows a more normal, instantiated pattern, and none of its methods should be referenced as static.
Console::log()
This logging method will log a string or any other variable into the 'messages' area of the display. Anything that can be handled with a print_r
can be passed in.
Console::logMemory()
This logging method can either log the current memory usage of the application (for benchmarking) or the memory usage of a given object.
Console::logError()
This logging method extracts some information from an Exception object for display. You can wire this up with an error handler to track unexpected errors, though the accuracy of the displayed data may be lacking.
Console::logSpeed()
This logging method takes a snapshot of the current time. The usefulness of this snapshot depends on how well you wire up the profiler start time.
PhpQuickProfiler
The PhpQuickProfiler class handles collection of basic system metrics, performs some mapping, and passes data off to a Display object. It also will handle much of the query analysis if you set up things appropriately.
PhpQuickProfiler::__construct()
This method returns a new instance of the profiler (no surprises here). The one catch is for timing. If you are interested in tracking load times and accurate speed points you'll need to be aware of when you instantiate this object.
By default, all elapsed times are based on when this object gets constructed. So, you'll want to create an instance of PhpQuickProfiler very early on in your application. There is an alternative if you want to wait for creation - the first parameter of PhpQuickProfiler::__construct()
can be a microtime double that represents the starting time of the application.
PhpQuickProfiler::setConsole()
This method sets the Console object that contains all pertinent logging information for the application runtime. This is different from the original Particletree, where the profiler 'assumes' that a global static Console object would contain the data.
PhpQuickProfiler::setDisplay()
This method sets a customized Display object into the profiler for later invokation. This is different than the original Particletree, which had no concept of a Display object. Because of that, this method is optional. If it is not used, a clean Display object will be used for the display.
See the Display class for some of the options.
PhpQuickProfiler::setProfiledQueries()
This method sends in a list of query profile information for analysis. This information must be passed in an expected format. While this method is optional, it is one of the easier ways to pass in data for query analysis.
The format is very important, as any deviation will not be understood. For example, Aura.Sql includes an optional profiler that returns data in a more modern format. To map to this expected format you must do some manipulation.
Any statement that can be handled by prepending an EXPLAIN
can be passed to this. Also, for this to do anything, you MUST pass in a database connection into the display
method below.
PhpQuickProfiler::display()
This method kicks off the display functionality, which is basically spewing out HTML and styles and such. It also kicks off a lot of the query analysis and metric gathering, which eats up (not much) some memory, so it's only recommended to call this in development or controlled environments. It takes a single parameter, a database connection, that must have a basic PDO-like interface.
To sum this up, for query analysis to work, you must pass in this db connection and do one of two things:
- inject the profiledQueries into PhpQuickProfiler::setProfiledQueries() before display is called or
- have a property of
queries
in the database connection that contains an array of profiled queries in the expected format.
The second option is to preserve semi-backwards compatability with the original Particletree release.
Display
The Display class is usually not interacted with. It manipulates the data from PhpQuickProfiler into a display-friendly format. It does have a few optional construct methods that need to be built upon with future releases.
Tests
To execute the test suite, you'll need phpunit (and to install package with dev dependencies).
Contributing
Please see CONTRIBUTING for details.
Learn More
Credits
- Ryan Campbell (original)
- Kevin Hale (original)
- Jacob Emerick (refactor)
License
PHP Quick Profiler is licensed under the MIT license. See License File for more information.