PHP script scheduling without cron job
Sometimes a website built in php needs to schedule a script on daily or hourly basis – for example, Reminder Emails, Newsletter emails or Database backups to be taken automatically. Normally, these types of backend tasks can be handled with the help of cron jobs but sometimes on shared hosting cron job or windows scheduler is not available.
One alternative to cron jobs is phpjobschedular library. The steps to work with phpjobschedular are:
– Go to http://www.dwalker.co.uk/downloads/ to download phpjobschedular
– Click on phpjobscheduler.3.9.zip to download phpjobschedular library.
– Extract zipped folder. Copy Extracted phpjobschedular folder at a location inside your website folder.
– Suppose you have copied folder to abcdomain.com/Library. Edit database configuration information in
– Now inside any html or php page’s code add following statement (for example inside home page or index page or any other page which is visited often):
– Write your script regarding email or any database insertion/updation activities in phpjobschedular/eg_email_site_stats_to_boss.php file.
– Now, open the link: abcdomain.com/Library/phpjobscheduler/pjsfiles/?add=1
– You can change value from dropdowns according to your requirements. Suppose, you want to run your script automatically every day, then you will select value 1 from Daily Dropdown. If you
want to run your script every hour, then your will select value 1 from Hourly dropdown.
– After clicking on Add Job button, two tables will be created in database:
– Working of this type of phpjobschedular is as follows:
If you set daily execution at 8:00 PM on Nov 01, 2016, then next fire time will be set as 8:00 PM Nov 02, 2016. Similarly if you set hourly schedule for your website and your website receives first hit at 8:00 PM, then next schedule for script run will be set as 9:00 PM. In between 8:00 and 9:00 PM, script will not run because next scheduled time is 9:00 PM. Suppose, website will not receive any hit until 11:30 PM, then script will run at 11:30 PM and next scheduled time will be set as 12:30 AM.
In this way, phpjobschedular runs required script automatically without use of cron job or crontab.