Page 1 of 1
How we can make an cronjob in php ???
Posted: Sat Oct 20, 2007 8:03 am
by djdon11
hi friends ..
i want to send email on every fifth day to my users ..
for this i have to run my php script page on every fifth day automatically & for this i think i need an cronjob which run my page automatically on every fifth day .. on server
anybody let me know how to make an cronjob & how we can set it on our server ..
i don't know anything about the cronjob .......
please help me it is urgent

Posted: Sat Oct 20, 2007 8:16 am
by Josh1billion
You go into your control panel (of your webhosting account) and there should be an option for Cron Jobs somewhere there. Go there, and tell it the command (for PHP files, I'm not sure if you just type the name of the php file or if you have to type something else.. I think you have to type something else, google "php cron jobs" "cron jobs php script" or something) and you tell it how often to do it (every 5 days).
if there is any othere way to mail instead of set a cronjob?
Posted: Sat Oct 20, 2007 8:39 am
by djdon11
hi..
Thanks for your reply ..
i want to know if there is any other way to for sending emails automatically on every fifth day .. instead of set an creonjob on server ?
if there is any idea then please let me know ... i need it urgently ...
Thanks ....
Posted: Sat Oct 20, 2007 9:04 am
by aaronhall
If you did it another way, you'd be reinventing the wheel. Why not cron?
Also, we typically stone people who double post...
Posted: Sat Oct 20, 2007 9:25 am
by Josh1billion
Well, there is one other way. If you have high traffic to your website, this will work very well, but if you don't, it might not.
What you do is have an integer in your database, in a table, which keeps track of the time that you sent your last e-mail. It should be in timestamp form (the code date("U") will give you the current time in timestamp form). Then, in your PHP code that is executed whenever someone visits your website, you check the last time that you sent an e-mail (with that integer in your database) and see if it was at least five days ago. If true, you send out an e-mail and update the time.
Note that when updating the time, it would usually be best to add five days (in seconds) to that value rather than just update it with the current time. Just make sure that the value you start with (before you ever run the script) is recent, and not 0 or something (because if you're adding to the current time, and you start with 0, it would be sending years' worth of e-mails-- so have the value start at the timestamp of today or yesterday or five days ago or something rather than 0).
Also, this method will only work if you have decent traffic to your site, because the check will only take place whenever someone visits your site. As long as you get one hit per day, though, it should be fine... though if you want your e-mails sent around the same time every day, you'd want a visitor every hour or whatever. A visitor every hour would mean that the e-mails would be sent around the same time (within the same hour) of every 5th day-- example: every 5th day somewhere between 1:30 and 2:30.