
如何在 PHP 中查看页面运行时间
PHP 提供了多种方法来测量和显示页面运行的时间,这是优化网站性能的重要指标。
1. 使用 microtime() 函数
2. 使用 gettimeofday() 函数
3. 使用 performance_get_function_timing() 函数
在 PHP 8.0 中引入了 performance_get_function_timing() 函数,它提供了更详细的页面性能信息,包括执行时间。
4. 使用 Xdebug 扩展
Xdebug 扩展提供了更全面的性能分析工具,包括测量页面运行时间的选项。要使用它,需要安装并配置扩展。
在脚本的开头添加以下代码:
xdebug_start_profiling();
在脚本的结尾添加以下代码:
xdebug_stop_profiling();
运行脚本后,可以在 Xdebug profiler 中查看页面运行时间和其他性能指标。

