Now i had read a post online for alternative to cron jobs, that :
CODE
Now depending on the actual functionality of the script (if its just a php page that needs to be executed). You could create a simple database that holds the last time executed, and a script included on your website that checks to see the last time it was executed and if its longer then X amount of time, execute it again. (use some ajax or something to do it behind the scenes)
Now its not the first time ive heard this. A popular, unique online web based game i play (legacy-game.net) uses this method of cron jobs.
Can anyone post a script or help for this? Is there any online script for this sort of thing?
And if you could , could you please list a proper step-by-step way to mimic cron jobs.
I sort of understand how to do it, but i dont get the part on how to manipulate time..etc. I mean to check the time with php with the time in the mysql database.
Nevermind , i got it. Easier then i thought!
Anyways, I'm gonna guide all the newbs and people who might need help in the future with this :
This script is for running on an hourly basis. How it is to be run, that is upto you. You can use ajax or anything. I have put it on all of my pages(basically ive put it in one page which is required in all pages) and once that page is visited, the page is run.
CODE
<?php
echo "<Br /> CRONJOB DETAILS : <br />";
//create a variable which contains the current hour of the server(from 1 - 12)
$timetocheck=date(g);
//select the database table which contains the cronjob details
$select=mysql_query("SELECT * FROM cron");
$time=mysql_fetch_array($select);
//setting the variable $timetoadd to the data of $timetocheck
$timetoadd=$timetocheck;
//echo "Last time executed : $time[last_executed]";
//checking if the current time (in hour from 1-12) is not equal to the time given in the database of which the last cron was executed
//if it is not, then it will initiate the required cron jobs along with updating the value for last_executed time in the database.
if ($timetoadd != $time[last_executed]) {
$q=mysql_query("UPDATE cron SET last_executed='$timetocheck'");
require('../crons/turns.php');
echo "<br/>The Following Crons have been run :</br>";
echo "-Turns Update Cron (+200/h)<br />";
}
else {
echo "<br />No cron is currently being run.<br />";
}
?>
echo "<Br /> CRONJOB DETAILS : <br />";
//create a variable which contains the current hour of the server(from 1 - 12)
$timetocheck=date(g);
//select the database table which contains the cronjob details
$select=mysql_query("SELECT * FROM cron");
$time=mysql_fetch_array($select);
//setting the variable $timetoadd to the data of $timetocheck
$timetoadd=$timetocheck;
//echo "Last time executed : $time[last_executed]";
//checking if the current time (in hour from 1-12) is not equal to the time given in the database of which the last cron was executed
//if it is not, then it will initiate the required cron jobs along with updating the value for last_executed time in the database.
if ($timetoadd != $time[last_executed]) {
$q=mysql_query("UPDATE cron SET last_executed='$timetocheck'");
require('../crons/turns.php');
echo "<br/>The Following Crons have been run :</br>";
echo "-Turns Update Cron (+200/h)<br />";
}
else {
echo "<br />No cron is currently being run.<br />";
}
?>

