You guys are close. Rather than put the periodic functions in the actual PHP of the page the user is requesting, have a javascript request happen from the user's page. This way, you can be certain that the page load will not be slowed down, and the javascript will fire onLoad(). Keep the stored 'last processed' value as suggested above, and only run the cron function once in a given interval.
Here's the JS to use to call something remotely. It will only work in modern browsers with JS enabled of course...
<script>
function DoCron()
{
var xhr;
try { xhr = new ActiveXObject('Msxml2.XMLHTTP'); }
catch (e)
{
try { xhr = new ActiveXObject('Microsoft.XMLHTTP'); }
catch (e2)
{
try { xhr = new XMLHttpRequest(); }
catch (e3) { xhr = false; }
}
}
xhr.onreadystatechange = function()
{
if(xhr.readyState == 4)
{
if(xhr.status == 200)
{
alert("Cron Worked");
}
else
{
return 'ERROR';
}
}
};
xhr.open("POST", "CRON.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send('');
}
</script>