pull-icon
logo-mobile

Not logged in

Your Account

Automated Cron Job Script

Home/Tutorials/Automated Cron Job Script

Automated Cron Job Script

Content by: Steve Stewart

Posted a year ago with 749 views

Cron job update automation

How to automated php scripts using a Cron Job, you can do this for any script from deleting old record in you're database to sending out mass emails to you're members.
In this tutorial, we are just going to do an update every day, so lets start off with some php.
The code below is an update script, firstly create a folder and call it: mycronjobs
Once you've done that, save the code below as: update_cron.php and upload the folder with the cron script to you're server.
This is very basic and will change the siteinformation name row in you're database and will start you off using cron jobs.


<?php
require_once("../dbconnection.php");

mysqli_qurey($db_conx, "UPDATE `siteinformation` SET `name`='MyUpdated Site Name'");

Now goto you're hosting provider and in you're cPanel Control look for Cron Jobs. (Depending on hosting provider will depend on the layout).



Creating the cron job:



In most instances you can select by dropping the box "Common Settings", and select Once a Day.
Then you need the root path to the script and as you see in mine, General example, I copy it all and paste it into the Command line, changing the part after "public_html" to the folder created, "mycronjobs" and the php file itself.