Created
June 19, 2023 21:04
-
-
Save Mwni/b84d64034e5724b63d01b116a4b5276a to your computer and use it in GitHub Desktop.
Simple PHP script for logging page load times. Will create a text file named "loadtimes.txt" in the working directory. Only use this for testing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$starttime = microtime(true); | |
// PAGE CODE GOES HERE | |
try{ | |
$endtime = microtime(true); | |
$duration = $endtime - $starttime; | |
$date = new DateTime(); | |
$timestamp = $date->format('Y-m-d H:i:s.u'); | |
$entry = sprintf("[%s] %.5f seconds for %s\n", $timestamp, $duration, $_SERVER['REQUEST_URI']); | |
$handle = fopen('loadtimes.txt', 'a'); | |
if(flock($handle, LOCK_EX)){ | |
fwrite($handle, $entry); | |
fflush($handle); | |
flock($handle, LOCK_UN); | |
} | |
fclose($handle); | |
}catch(Exception $e){} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment