John_S Posted April 5, 2009 Share Posted April 5, 2009 Hello everybody,I am trying to write a function which would work similarly to a cron job, each time a visitor will come to my site, the cron function will be called and will check if there is a cronjob to execute. I want to store all the cronjobs within a flat file so there won't be too many connections to the database. However when I test my function it refuses to work, it doesn't output any errors at all, but there is no result displayed neither the flat file database is changed. Could somebody please tell me what's wrong? Here's my code: function cron($name) { $file = file('./crons/crons.db.php'); foreach ($file as $line) { if(ereg("$name", $line)) { $cronjob = explode("|", $line); if (time() >= $cronjob[2]) { include("./crons/$name.cron.php"); } } } // End of Foreach $source = fopen('./crons/crons.db.php', w); foreach ($file as $line) { if(!ereg("$name", $line)) { fwrite($source, $line); } else { $lastrun = time(); $toberun = time() + (24 * 60 * 60); fwrite($source, "|$name|$lastrun|$toberun|$status| "); } } } // End of Fucntion In my files, I call the function like this: cron("db_backup"); [db_backup = databse backup.] Thanks a lot in advance!Yours John_S Quote Link to comment Share on other sites More sharing options...
shlumph Posted April 5, 2009 Share Posted April 5, 2009 <?php function cron($name) { $file = file('./crons/crons.db.php'); foreach ($file as $line) { if(ereg("$name", $line)) { $cronjob = explode("|", $line); if (time() >= $cronjob[2]) { include("./crons/$name.cron.php"); } } }//End of Foreach $source = fopen('./crons/crons.db.php', w); foreach ($file as $line) { if(!ereg("$name", $line)) { fwrite($source, $line); } else { $lastrun = time(); $toberun = time() + (24 * 60 * 60); fwrite($source, "|$name|$lastrun|$toberun|$status| "); } } }//End of Fucntion ?> Quote Link to comment Share on other sites More sharing options...
John_S Posted April 10, 2009 Author Share Posted April 10, 2009 Thanks a lot! Quote Link to comment Share on other sites More sharing options...
shlumph Posted April 10, 2009 Share Posted April 10, 2009 You know I did nothing except format your code correctly, right? LOL, glad to hear it works though. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.