+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12

Thread: PHP cron job question

  1. #1
    Join Date
    Jul 2006
    Posts
    29

    Question PHP cron job question

    Hi all,

    Sorry if this sounds dumb but what command do I put down to run a PHP script?

    I have a PHP script that would be say /email.php and I want to run this, what command do I have to type into the cron thingy in cPanel?

    Cheers

    Paul.

  2. #2
    Join Date
    Jul 2006
    Location
    Portland, OR
    Posts
    280

    Default

    Quote Originally Posted by probedb
    what command do I put down to run a PHP script?

    I have a PHP script that would be say /email.php and I want to run this, what command do I have to type into the cron thingy in cPanel?
    The PHP interpreter is called php and it's at /usr/bin/php. The /usr/bin directory is probably on the execution path list so you may not need the prefix but it never hurts to add it. Also, you'll want to make use of the $HOME variable - this variable contains the name of the directory that contains your public_html.

    Unless you also need to be able to access such scripts from the web I would recommend not placing them in the public_html sub-tree since anyone in the world can run it (assuming they know its name, of course). So let's assume that you create a directory called "script_dir" that is a peer of public_html and you place email.php in that directory. The cron command to execute the script would be:
    Code:
    /usr/bin/php $HOME/script_dir/email.php
    In some cases, it is useful or necessary for the "current directory" to be the script directory while it executes. This can be arranged using a slightly more complicated cron command:
    Code:
    (cd $HOME/script_dir; /usr/bin/php email.php)

  3. #3
    Join Date
    Jul 2006
    Posts
    29

    Default

    Awesome, thanks very much for that Working a treat....except that the simple view doesn't work properly! Ah well managed to sort it using the Unix view to get it working every hour.

  4. #4
    Join Date
    Mar 2007
    Posts
    1

    Default

    hey, another newbie need help with cron... similar challenge to the one above...

    So if I need to get the file 'email.php' (which resides in "public_html/mydir" ) in the cron path then what I need to enter in the field is:

    /usr/bin/php $HOME/public_html/email.php

    Is this correct? Exactly as it's mentioned above?

  5. #5
    Join Date
    Jul 2006
    Location
    Portland, OR
    Posts
    280

    Default

    Quote Originally Posted by rpl View Post
    So if I need to get the file 'email.php' (which resides in "public_html/mydir" ) in the cron path then what I need to enter in the field is:

    /usr/bin/php $HOME/public_html/email.php

    Is this correct?
    If the script is in 'my_dir' you need to include that in the path, too:

    /usr/bin/php $HOME/public_html/my_dir/email.php

  6. #6
    Join Date
    Mar 2009
    Location
    USA
    Posts
    1

    Default PHP cron job question

    Im trying to execute a php file at intervals using cron. if i call the file from my web browser it runs fine , but if i setup a cron job in cpanel , when the script runs , it just emails me a bunch of errors. is their anyway i can make this happen with cron?
    Last edited by cade; 03-08-2009 at 10:05 PM. Reason: Neither "signatuer"s nor signatures are allowed for new members.

  7. #7
    Join Date
    Nov 2006
    Location
    Sydney, Australia
    Posts
    4,533

    Default

    Does your script have include files? if so then the problem might be that the root folder is two folders higher for the cron job than it is for the same job run from a browser - the home or home1 folder rather than public_html.

  8. #8
    Join Date
    Jan 2010
    Posts
    14

    Default

    I had a cron job to run a PHP script working once before, but I deleted it and now I forget how I had it setup and thought I'd ask for some clarification because I'm confused by the differences between what I've seen posted in threads about this.

    Which of these is best, or does it matter?

    For the first half of the command, the path to PHP:
    1. Code:
      /usr/local/bin/php
    2. Code:
      /usr/bin/php
    3. Code:
      php

    For the second half of the command, the path to the file:
    1. Code:
      /home/public_html/mydir/thefile.php
    2. Code:
      $HOME/public_html/mydir/thefile.php
    3. Code:
      $HOME/mydir/thefile.php
    Last edited by toronado; 07-29-2010 at 02:23 PM.

  9. #9
    Join Date
    Aug 2010
    Posts
    2

    Default

    I use "php /home4/qalistsc/public_html/folder/xxx.php" at cron job option.. and it run well

    http://www.qalists.com
    http://www.beegadget.com
    http://www.feeddiary.com
    http://md5pass.com
    http://www.liputra.com
    Last edited by jepes; 08-10-2010 at 07:48 AM.

  10. #10
    Join Date
    Nov 2006
    Location
    Sydney, Australia
    Posts
    4,533

    Default

    The first two values in the path (before public_html) will depend on exactly where your account is on the server.

    The first will be "home" possibly with a number on the end and the second will be your account name. You'll have to check in cPanel for the exact details.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts