klenwell information services : HostingAdminCron

Cron Jobs

The examples below represent various ways to set up a cron job for a Php script in a cPanel shared hosting environment.

PHP Script on cPanel

Some ways to run a PHP script with cron on cPanel:

wget -O /dev/null http://www.domain.com/script.php

lynx is a text-based web browser commonly available on linux servers (wikipedia)
lynx -dump 'http://www.domain.com/script.php'

note: this will not run the script as in a browser, which may lead to unexpected results. for instance, GET variables cannot be set in the url.
php -q /usr/home/USERNAME/script.php

/usr/bin/php -q /usr/home/USERNAME/script.php

note: I've encountered shared hosting environments where GET is not available
GET 'http://domain.com/script.php' > /dev/null

Note on GET Variables

If you want to include GET variables in your cron job (like me), put your url in single quotation marks. Otherwise, they will get cut off. An explanation can be found here:
GET variables get truncated, so you have to wrap the url in quotes to make it work... This is because the shell will try to expand the arguments to 'open' and ? happens to be a shell wildcard character.

Simple Test Script

Upload this script to your server and set up a cron job to run it as a simple test:


// a simple script to test cron jobs

echo "<h1>Cron Test</h1>";

if ( $_GET['cron'] = 'cron' ) echo '<p>GET ?cron=cron recognized</p>';



Project 1020 Page