Reputation: 1605
I need to update some records in the database on the 5th of every month. i know its time dependent so either i'll have to rely on server time or client time. As client time isn't reliable and my server is located in a different time zone and country, what is the best way to accomplish this?
Upvotes: 1
Views: 120
Reputation: 46900
Lets say your time is 5 hours ahead of your server time and you want to have this job run at 10 am your time, then you can simply schedule it to run at 5 am on 5th of each month. Now even if you change your computer's clock this will not effect server time. Unless you change server time. You can schedule a cron job to run like that easily.
Edit: There is no other reliable way of scheduling that I know of. for NIX based systems its cron jobs and for windows its task scheduler. However if you rely on client connection being open at 10 am on every 5th then rather do it manually, cause its no more automated then as you asked. I don't really know if there are more ways, but best yes surely, for me, is Cron Job.
Also, for cron jobs you do not need to write any code. You can call your existing PHP script on a scheduled time by the cron job manager itself. It just needs to see which program to call, which on your cause is php and then which file to call.
Edit
Since you mentioned you use a cPanel, here is the guide on cPanel from official cPanel documentation
Upvotes: 1