Download the PHP package tox82/server-timing-helper without Composer
On this page you can find all versions of the php package tox82/server-timing-helper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tox82/server-timing-helper
More information about tox82/server-timing-helper
Files in tox82/server-timing-helper
Package server-timing-helper
Short Description A simple helper class for Server Timing. Easily profile your code's execution time and send it to the client via the Server-Timing header.
License GPL-3.0-or-later
Informations about the package server-timing-helper
Server Timing Helper
A Simple Tool for Benchmarking Your PHP Code
The ServerTiming
class is designed to assist developers in measuring and logging the execution time of various code segments within a PHP application. By utilizing this class, you can initiate and terminate timers for different metrics, transmit these metrics to the client via the Server-Timing header, and record the results to a file. This is particularly useful for performance monitoring and optimization.
This tool is based on the Server Timing specification. You can learn more about it on web.dev.
Installation:
Usage
The profile Method
This is the easiest way to use the ServerTiming
class. It automatically handles the start/stop methods, and logs the results to the Network/Timing
panel in your browser's DevTools
.
The start/stop Method
Alternatively, you can manually control the start and stop methods by using start/stop
instead of profile
:
Saving the Output to a Log File
The log
method enables you to write detailed log entries for your metrics to a file.
This requires you to have a valid, writeable log file, but IMO it makes it a little bit easier to read the metrics.
You can use nested blocks to log the execution time of specific parts of your code. My suggestion is to add some spaces to the beginning of the nested blocks to make it more readable.
Setting a Custom Log File
By default, Server Timing Helper
attempts to find the apache error_log file path for logging. However, you can specify a custom log file path using the setLogFile
method. Make sure to set the log file path before using the log
method.