Home >Backend Development >PHP Tutorial >How Can I Monitor PHP Script Execution Time within the Script Itself?
Monitoring Script Execution Time in PHP
In PHP, tracking script execution time is crucial for enforcing the max_execution_time limit. However, is it possible to access this information within the script itself?
Solution
To monitor the wall-clock time (rather than CPU execution time), utilize the following code:
// Start time $time_start = microtime(true); // Script execution for($i=0; $i<1000; $i++){ // Perform operations } // End time $time_end = microtime(true); // Execution time computation $execution_time = ($time_end - $time_start)/60; // Output echo '<b>Total Execution Time:</b> '.$execution_time.' Mins';
Note:
This method includes time spent waiting for external resources (e.g., database), which is not considered in the max_execution_time limit.
The above is the detailed content of How Can I Monitor PHP Script Execution Time within the Script Itself?. For more information, please follow other related articles on the PHP Chinese website!