」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > 如何精確測量PHP腳本運行時間?

如何精確測量PHP腳本運行時間?

發佈於2025-04-18
瀏覽:405

How Can I Measure PHP Script Execution Time?
在PHP

中獲取腳本執行時間,跟踪腳本執行時間至關重要,對於執行max_execution_time限制。但是,有沒有辦法從腳本中訪問此信息? This question arises when you want to track CPU usage during PHP execution, excluding time spent waiting for database responses.

For Linux-based systems, if you only require wall-clock time (total time since the script's execution started), here's how you can calculate it:

// Start the timer at the beginning of the script $ time_start = microtime(true); //在這裡執行您的腳本 //停止計時器 $ time_end = microtime(true); //計算執行時間 $ execution_time =($ time_end -$ time_start) / 60; //顯示執行時間 迴聲'總執行時間:'。 $ execution_time。 'mins';

請注意,此方法包括等待外部資源的時間,與Max_execution_time不同,它僅考慮PHP執行時間。

最新教學 更多>

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3