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

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.

You coudl use exec() and pass the cron command as an argument.

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

I figured it out.

Thanks. :smiley:

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.

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

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