SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Sep 2011
    Location
    California
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cron Jobs and PHP

    Hello,

    I am curious as to how one would go about executing a PHP script via cron job.

    I have a script that will send me a simple email.
    I would like a cron job to execute the script once an hour.
    How could I go about doing this?

    I am running on the Apache module.

    Thank you,

    Eric

  2. #2
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,206
    Mentioned
    74 Post(s)
    Tagged
    3 Thread(s)
    I did mine through cpanel and its quite straight forward. From memory you need to add php to the front of the path to the code.

  3. #3
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You coudl use exec() and pass the cron command as an argument.

  4. #4
    SitePoint Member
    Join Date
    Sep 2011
    Location
    California
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey again,

    I'm attempting to do mine through cPanel as well.
    Do I just give the file path where it says "command"?

    Thanks again,

    Eric

  5. #5
    SitePoint Member
    Join Date
    Sep 2011
    Location
    California
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I figured it out.

    Thanks.

  6. #6
    SitePoint Member
    Join Date
    Dec 2009
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What a Cron command looks like in CPanel

    We use a lot of cron scripts too and since no one has posted an example on this thread, I thought I would for anyone looking for an example.

    "/usr/bin/php" "/home/myserver/scripts/cron/queue-message.php" >& /dev/null

    For schedule of script execution you need to understand how the five parameters work (minute, hour, day, month and weekday) and once you've
    got a grasp of these, execution of scripts is pretty flexible for when you want to.
    http://www.webpagefavs.com/

    Newly launched social bookmark website free for all to use, for commercial use promote your website, products or services cheaply.

  7. #7
    SitePoint Member
    Join Date
    Nov 2011
    Location
    Annapolis, MD
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using cpanel you can call a shell script that isn't located in your public_html folder:
    /home/username/bin/scripts/cron_file.sh

    Or you can use curl to call a page on your site:
    curl http://www.example.com/cron.php

    Or you can call php to run a file
    /usr/local/bin/php -q /home/username/public_html/mysite/cron.php

    All of these are valid cpanel cron jobs
    Last edited by trailsix; Nov 21, 2011 at 22:18. Reason: I don't want to link to example.com

  8. #8
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi guys,

    My host’s cron (Server API: CGI/fastCGI) support absolute URL of the php like: (http://www.mysite/example.php )

    But what I’ve got is a command:
    php "/web/mysite/mysite.com/administrator/components/comex/helpers/cron.php" username="admin" passwd="adminpass" template_id="50"

    Is there possible to execute this command with custom php?(or I’m not sure the host enable .sh if so, how can I put the php command in the shell script to get the cron the full URL path?)
    Could somebody help me out how can I solve it?

    Thanks in advance
    gizda


Bookmarks

Posting Permissions

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