{"id":22705652,"url":"https://github.com/tox82/server-timing-helper","last_synced_at":"2026-01-02T21:04:13.053Z","repository":{"id":65685821,"uuid":"597346198","full_name":"ToX82/server-timing-helper","owner":"ToX82","description":"A simple Server Timing helper class. Make it easy to profile your code's execution time and send it to the client","archived":false,"fork":false,"pushed_at":"2024-07-24T15:13:15.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-14T01:04:18.367Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ToX82.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-04T08:57:43.000Z","updated_at":"2024-07-24T15:11:31.000Z","dependencies_parsed_at":"2024-07-24T17:29:15.533Z","dependency_job_id":"531face8-afc0-43e0-8190-b64bb183fe84","html_url":"https://github.com/ToX82/server-timing-helper","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"24b1c2396f8e2b6c58603f208f15f53d55e80fcb"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ToX82%2Fserver-timing-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ToX82%2Fserver-timing-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ToX82%2Fserver-timing-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ToX82%2Fserver-timing-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ToX82","download_url":"https://codeload.github.com/ToX82/server-timing-helper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243589328,"owners_count":20315471,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-10T09:12:32.307Z","updated_at":"2026-01-02T21:04:08.017Z","avatar_url":"https://github.com/ToX82.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Server Timing Helper\n## A Simple Tool for Benchmarking Your PHP Code\n\nThe `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.\n\n![server-timing](https://user-images.githubusercontent.com/659492/216758847-673f1155-db52-48a8-aada-3648b7c837cf.png)\n\nThis tool is based on the [Server Timing](https://www.w3.org/TR/server-timing/) specification. You can learn more about it on [web.dev](https://web.dev/custom-metrics/?utm_source=devtools#server-timing-api).\n\n# Installation:\n-----------\n```shell\ncomposer require tox82/server-timing-helper\n```\n\n# Usage\n-----------\n\n## The profile Method\nThis 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`.\n\n```php\n\\Tox82\\ServerTiming::profile('metricName');\n# ... your code here ...\n\\Tox82\\ServerTiming::profile('metricName');\n```\n\n## The start/stop Method\nAlternatively, you can manually control the start and stop methods by using `start/stop` instead of `profile`:\n\n```php\n\\Tox82\\ServerTiming::start('metricName');\n# ... your code here ...\n\\Tox82\\ServerTiming::stop('metricName');\n```\n\n## Saving the Output to a Log File\nThe `log` method enables you to write detailed log entries for your metrics to a file. \nThis requires you to have a valid, writeable log file, but IMO it makes it a little bit easier to read the metrics.\nYou 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.\n\n```php\n\\Tox82\\ServerTiming::log('heavyBlocks');\n# foreach ($items as $item) {\n\\Tox82\\ServerTiming::log('    singleBlock');\n# ... your code here ...\n\\Tox82\\ServerTiming::log('    singleBlock');\n# }\n\\Tox82\\ServerTiming::log('heavyBlocks');\n```\n![server_timing](https://github.com/user-attachments/assets/e8c46310-1671-4239-86a6-7da293e5d371)\n\n\n## Setting a Custom Log File\n\nBy 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.\n\n```php\n\\Tox82\\ServerTiming::setLogFile('/var/www/server_timing.log');\n```\n\n# Resources\n---------\n * [Report issues](https://github.com/ToX82/server-timing-helper/issues)\n * [Send Pull Requests](https://github.com/ToX82/server-timing-helper/pulls)\n * [Check the main repository](https://github.com/ToX82/server-timing-helper)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftox82%2Fserver-timing-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftox82%2Fserver-timing-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftox82%2Fserver-timing-helper/lists"}