PHP won't let page update automatically every day/6 hours
A friend build a ranking system on his site and I am trying to host in on mine via wordpress and godaddy. It updates for him but when I load it to my site, it works for 6 hours, but as soon as the reload is supposed to occur, it errors and I get a 500 timeout error.
His page is at: http://www.jeremynoeljohnson.com/yakezieclub
My page is currently at http://sweatingthebigstuff.com/yakezieclub but when you ?reload=1 it will give the error.
Any idea why this might be happening? Any settings that I might need to change?
I can give you all the code, but which part? the index.php file? I'm not sure which part is messing up. I literally uploaded the same code as him.
Here's the reload part:
$cachefile = "rankings.html";
$daycachefile = "rankings_history.xml";
$cachetime = (60 * 60) * 6; // every 6 hours, the cache refreshes
$daycachetime = (60 * 60) * 24; // every 24 hours, the history will be written to - or whenever the page is requested after 24 hours has passed
$writenewdata = false;
if (!empty($_GET['reload']))
{
if ($_GET['reload']== 1)
{
$cachetime = 1;
}
}
if (!empty($_GET['reloadhistory']))
{
if ($_GET['reloadhistory'] == 1)
{
$daycachetime = 1;
$cachetime = 1;
}
}
if (file_exists($daycachefile) && (time() - $daycachetime < filemtime($daycachefile)))
{
// Do nothing
}
else
{
$writenewdata = true;
$cachetime = 1;
}
// Serve from the cache if it is younger than $cachetime
if (file_exists($cachefile) && (time() - $cachetime < fil开发者_运维百科emtime($cachefile)))
{
include($cachefile);
echo "<!-- Cached ".date('jS F Y H:i', filemtime($cachefile))." -->";
exit;
}
ob_start(); // start the output buffer
?>
Any particular reason you're starting output buffering after the cache file is included? If the cache file is just raw html, it'll have to dumped into the output stream already, followed by the cache date comment before you start buffering.
Is it possible that perhaps that something in the script (or another script) is slapping a lock on the output file, such that the reload checking portion hangs while waiting for the lock to clear?
It seems really slow, which makes me thing you're doing something very intensive or something with a high latency. If your web server is hitting its internal timeout value, then you'll get a 500 error. Optimize your code for better speed or increase your server's timeout to fix this problem.
If you post your server platform, I can let you know what you can do to increase the timeout.
Hope this helps.
Two leads :
First, check that your file system returns actual date/time when creating a new file. On some systems, file modification time are localized to a timezone, on other they aren't (GMT instead).
Secondly, be careful using filemtime. PHP use a cache system to avoid access to hdd ressources, this is great, but I never find out how this cache is managed internally and is lifetime. I recommend calling clearstatcache at every time you run the update script
精彩评论