The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

CRON with PHP and database? [moved]

Discussion in 'Database Discussions' started by jpistone, Sep 2, 2005.

  1. jpistone

    jpistone Registered

    Joined:
    Jun 21, 2004
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    CRON with PHP and database?

    I have a database with individuals whom I would like to send an email to (on a regular basis) given certain changing parameters in the same database. If I run a PHP script, no problem. But I'd like to set it up as a CRON job that runs each morning c. 1am or so. Can I/How do I go about configuring the Standard option to tell the CRON to go to this particular .php file and execute it? I'm getting a 'permission denial' when I try to do that. All the tutorials deal with UNIX shell coding. I can't quite get the pieces together. The Server API is CGI. Thanks.
     
    #1 jpistone, Sep 2, 2005
    Last edited: Sep 2, 2005
  2. webignition

    webignition Well-Known Member

    Joined:
    Jan 22, 2005
    Messages:
    1,880
    Likes Received:
    0
    Trophy Points:
    36
    Check the permissions on the PHP script, making sure that CRON has the permission to execute it.

    Best start with 0755 permissions as this will definitely work, and then work down from there to something more secure if this bothers you.
     
  3. jpistone

    jpistone Registered

    Joined:
    Jun 21, 2004
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Thanks...that got me a little further. Now it's not doing a denial, but giving me the following:

    /home/username/cronmail.php: line 1: ?php: No such file or directory
    /home/username/cronmail.php: line 3: //: is a directory
    /home/username/cronmail.php: line 4: =: command not found
    /home/username/cronmail.php: line 5: .=: command not found
    /home/username/cronmail.php: line 7: .=: command not found
    /home/username/cronmail.php: line 8: Reply-To: webmaster@: command not found
    /home/username/cronmail.php: line 9: syntax error near unexpected token `('
    /home/username/cronmail.php: line 9: ` 'X-Mailer: PHP/' . phpversion();'

    It seems to have trouble with simple php syntax. Is there special coding that should go with a file meant for this?... special characters? The file is stashed in a directory that is being found
    and it's reading at this point it would seem. I appreciate your time.
     
    #3 jpistone, Sep 2, 2005
    Last edited: Sep 2, 2005
  4. webignition

    webignition Well-Known Member

    Joined:
    Jan 22, 2005
    Messages:
    1,880
    Likes Received:
    0
    Trophy Points:
    36
    You'll need the shebang line at the top, as through cron it'd be as if running from the command line and you'd need to tell it (cron) what to use to make sense of the code.

    In short, add the following as the very first line in the script:

    Code:
    #!/usr/local/bin/php
    and by very first line, I mean before absolutely everything else.
     
  5. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    Yup. If the script is expecting a web environment, you can also run it through curl.
     
  6. jpistone

    jpistone Registered

    Joined:
    Jun 21, 2004
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    That did it! Works like a charm! Thanks to all of you!
     
Loading...

Share This Page