tox82/server-timing-helper 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tox82/server-timing-helper

Composer 安装命令:

composer require tox82/server-timing-helper

包简介

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.

README 文档

README

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.

server-timing

This tool is based on the Server Timing specification. You can learn more about it on web.dev.

Installation:

composer require tox82/server-timing-helper

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.

\Tox82\ServerTiming::profile('metricName');
# ... your code here ...
\Tox82\ServerTiming::profile('metricName');

The start/stop Method

Alternatively, you can manually control the start and stop methods by using start/stop instead of profile:

\Tox82\ServerTiming::start('metricName');
# ... your code here ...
\Tox82\ServerTiming::stop('metricName');

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.

\Tox82\ServerTiming::log('heavyBlocks');
# foreach ($items as $item) {
\Tox82\ServerTiming::log('    singleBlock');
# ... your code here ...
\Tox82\ServerTiming::log('    singleBlock');
# }
\Tox82\ServerTiming::log('heavyBlocks');

server_timing

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.

\Tox82\ServerTiming::setLogFile('/var/www/server_timing.log');

Resources

统计信息

  • 总下载量: 4.45k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2023-02-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固