Download the PHP package chus/php-execution-tracker without Composer
On this page you can find all versions of the php package chus/php-execution-tracker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download chus/php-execution-tracker
More information about chus/php-execution-tracker
Files in chus/php-execution-tracker
Package php-execution-tracker
Short Description a PHP process execution tracker
License MIT
Informations about the package php-execution-tracker
PHP Execution Tracker
A PHP library to track the execution of a process. It allows you to track the time difference between processes, debug, logs, warnings and errors.
Important: Currently, I use this same library in production, but it is still subject to potential significant changes due to the early version it is in.
- PHP Execution Tracker
- Usage
- Result formats
- Array
- JSON
- HTML
- Result options
- Reduced
- With durations
- With human readable times
- Without timestamps
- Hiding traces
- Disabling the tracker
- Using the hide method
- Clearing the tracker
- Tracker static methods
- Development
- License
Usage
Install the library using composer:
Import the library:
Then, you can track the execution of a process like this:
Output:
Result formats
You can get the result in different formats:
Array
JSON
HTML
Result options
You can also get the result with different options:
Reduced
Get the result with a reduced version of the trace. This will remove the elements with false values (empty arrays, empty strings, etc.). Start and end times will be removed if the duration is minor than 1 second.
Output:
With durations
Get the result indicating all traces duration. This will add the duration of each trace to the result.
Output:
With human readable times
Get the result with human readable times. This will convert the timestamps to human readable times.
Output:
Without timestamps
Get the result without timestamps. This will remove the start and end times from the result.
Output:
Hiding traces
There are some cases where you want to hide a trace, for example, when you have a trace that you don't want to show in the result under some conditions.
Disabling the tracker
You can disable and enable the Tracker wethever you want. This will disable the tracking of the process and the creation of sub-traces.
Having this code:
Without disabling the tracker:
Output:
Disabling the tracker:
Output:
Using the hide method
You can also hide a trace using the hide
method:
In terms of performance, if you are going to call the "hide" method many times, is better to use Tracker::disable() and Tracker::enable() to disable and enable the tracker, respectively, instead of hiding traces.
Clearing the tracker
You can clear the tracker to remove all the traces and reset it.
Output:
You can also hide a unique trace:
Is better to use Tracker::disable() and Tracker::enable() to disable and enable the tracker, respectively, instead of hiding traces, due to the traces will be still stored in memory.
Tracker static methods
You can use the following static methods to interact with the tracker:
Tracker::track($name)
: Start tracking a process.Tracker::getCurrentTrace()
Get the current trace.Tracker::getMainTrace()
: Get the main trace.Tracker::clear()
: Clear the tracker.Tracker::disable()
: This will hide the traces created after calling this method until callingTracker::enable()
.Tracker::enable()
: This will enable the tracker.
Development
To run the tests, you can use the following command:
License
This library is licensed under the MIT license. See the LICENSE file for more information.