PHP quickies: Shared webhost Cronjobs!

This isn’t entirely PHP. In fact, its technically NOT PHP. I had to add it to have an idea how to do scheduled tasks for your PHP code (This post prepares you for my next post).

Alright, here we go!

Imagine this:

You wrote a nice PHP code that generates daily statistics, lets say visitors hits, and you want to email your users with the latest statistics be the end of each day (Which is literally the very beginning of the next day).

The easiest (And not probably the safest. But safe enough) is to write a nice “email.php” file that sends emails to users with stats when requested (This will be our subject tomorrow).

We’re technically done. All you need to do is set the file permission to 0740 and do the Cronjob as the following:

 X Y * * * wget

Where X and Y are minute hour in server time while the rest are starred so this cronjob would run daily.

Note that server time doesn’t have to be your local time. In fact, its not in so many cases. As in, your server would be 7 hours behind since its hosted in USA for example. So just Y+7 for example and you’re done!

Another thing to take into consideration is SSL certificate. For example, if your website runs through HTTPS, I recommend doing the following if AND ONLY IF you’re sure it is fine to ignore certificate verification:

 X Y * * * wget --no-check-certificate

Thats it for now, next PHP quickie will discuss how to write a file that is cronjob ready 😀

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.