Skip to content

Instantly share code, notes, and snippets.

@Echocage
Created August 9, 2016 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Echocage/a967c78a5baf367b7fc164cadf4dd37a to your computer and use it in GitHub Desktop.
Save Echocage/a967c78a5baf367b7fc164cadf4dd37a to your computer and use it in GitHub Desktop.
function recordStart($name)
{
global $startTimes;
$startTimes[$name] = time();
}
function recordStop($name)
{
global $startTimes, $file;
$stopTime = time();
$startTime = $startTimes[$name];
$runtime = $stopTime - $startTime;
$ptfile = fopen($file, 'rw');
$lines = array();
$found = false;
while ($line = fgets($ptfile)) {
$line = trim($line);
$arr = str_getcsv($line);
if(strlen($line) < 5){
continue;
}
$plr_name = $arr[0];
$timestamp = $arr[1];
if ($name != $plr_name) {
array_push($lines, $line);
} else {
$new_time = $runtime + $timestamp;
$new_line = $name . "," . $new_time;
array_push($lines, $new_line);
$found = true;
}
}
if (!$found) {
$new_time = $runtime + 0;
$new_line = $name . "," . $new_time;
array_push($lines, $new_line);
}
print_r($lines);
$end_lines = implode("\n", $lines);
print_r($end_lines);
file_put_contents($file, $end_lines);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment