Jump to content

slow logFile date check


jacko310592

Recommended Posts

hey guys,

 

i made a code which detects whether its a new month since the last time my website logFile was modified, then if it is it will rename the file and create a new blank logFile,  the only this is though is that its quite slow, it can somtimes take upto 2-3seconds to load on my home PC to load this one bit of code.

 

anyway, here is the code, can anyone think of a way in which this could be made faster?

 

$logfile = "{$ROOTdir}logs/logFile.txt";

$dateLastEdited = filemtime($logfile);
if (date("F", $dateLastEdited) != date("F")){
$dateOfLastEdit = date("F y", $dateLastEdited);
rename($logfile, "{$ROOTdir}logs/logFile ({$dateOfLastEdit}).txt");
$handle = fopen($logfile, 'a+');
fwrite($handle, $logline);
fclose($handle);
}

else {
$handle = fopen($logfile, 'a+');
fwrite($handle, $logline);
fclose($handle);
}

Link to comment
https://forums.phpfreaks.com/topic/188780-slow-logfile-date-check/
Share on other sites

it seem'd to happen whether it was creating the new file or appending the old,

 

i changed the

if (date("F", $dateLastEdited) != date("F")){
from a worded month to
if (date("m", $dateLastEdited) != date("m")){
numbered moth, which weirdly speeded it up, now it only seems to go slighly slower (takes about 1sec to load) when creating the new file.

 

but personally, i cannot see how the worded date can make it go any slower from the numbered one  :shrug:

 

oh well, atleast it works well now.

 

thanks for your post Buddski,  ill have a look into 'file_put_contents'

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.