Simpler CRON Jobbies on cPanel

Today I had a problem with a site I had a PHP script on, running as a cron job. Lo and behold, as I went through the directories via FTP, I found several hundred small files all looking somewhat like the PHP script path – here’s an example with details tweaked to protect the guilty:


The cron job to run it was this one:
*/15 * * * * wget
Which loads the myscript.php web page every 15 minutes, doing its business.

WGET is a handy tool to grab pages via URL rather than direct PHP calls – in this case, I needed to pass a parameter via $GET (?p=1234), and so a direct PHP call was awkward. I also wanted the option to call the file via my browser from time to time, so storing it out of the HTML document directories was not an option either.

However, I had cruft – and the cruft in my root directory was obviously related to this – in fact, each file seemed to be the page output, same as if I had it on my browser.

What to do?

  • The obvious answer in hindsight would be to dig around for the WGET option to not cache or log, and so not create any file. However, I thought originally the problem was ALL cron jobs, not just ones using WGET. Nonetheless, if you want, here is an option I found online (although didn’t test it, so Caveat emptor) which sends all output to /dev/null, effectively trashing it:
    wget -qO- &> /dev/null
  • Call PHP directly. While I was blaming cron generally, I tried a direct PHP call, like this:

    php /home/egwebsitecom/myscript.php >/dev/null 2>/dev/null

    On HostGator at least, this worked. One awkward thing: the command line parameters. To call that, I ended up creating two scripts – myscript0.php which called myscript.php.

    In myscript0.php I simply did this:

    include 'myscript.php';

    and in myscript.php I did this:
    if (defined('MYKEYVALUE'))
    // code to set the GET parameter(s) directly
    // code to set parameter(s) from the URL GET variables

    Now my file could be called directly in the browser, or via PHP in cron, bypassing WGET.

A few notes:

  • While trying these out, I recommend you add an email address via cron in cPanel to get reports – this is the easiest way to confirm everything is working.
  • As well, leave off the null output for now (the >/dev/null 2>/dev/null) so the result will be emailed to you, helping with troubleshooting.
  • Finally, while testing, bump up the cron time to say every 1 or 2 minutes for a little while, so you get responses fast – but don’t forget to slow it down after you’re done – servers don’t like a once a minute cron job!
End Date: Tuesday Mar-20-2018 14:40:57 PDT
Buy It Now for only: $3.49
Buy It Now | Add to watch list
Build Your Own Database Driven Website Using PHP & MySQL Paperback 2004 CHOP
$6.23 (0 Bids)
End Date: Friday Feb-23-2018 3:19:11 PST
Bid now | Add to watch list
jQuery 1.3 with PHP
End Date: Monday Mar-19-2018 21:03:28 PDT
Buy It Now for only: $5.86
Buy It Now | Add to watch list

3 thoughts on “Simpler CRON Jobbies on cPanel

  1. Thanks for the article. If you don’t have privilege to setup cron job, a third party webcron (like: may be a good option for you.

  2. I have been reading many articles of yours, or i presume they are your so I must congratulate you for some of the great information you publish. I am a novice of php but found one article on the internet where you made a php multiple random image script using the following:
    // rotate images randomly but w/o dups on same page – format:
    // – rotate image #0 – use ‘i=1’
    // for second, etc
    // (c) 2004 David Pankhurst – use freely, but please leave in my credit
    $images=array( // list of files to rotate – add as needed
    “smile.jpg” );
    $secondsFixed=10; // seconds to keep list the same
    for ($i=0;$i
    What I am wondering being new to php, is there a way to link the pictures to a web page so that when the pictures change they can be clicked upon to take that person to a page associated to the picture? I have tried several ways with your script, but not yet been able to get results. Keep up the great contributions, great reading all over the net

Leave a Reply to David Pankhurst Cancel reply

Your email address will not be published. Required fields are marked *