I realize that this post is already several years old but this one helped me the most so let me share my findings as well to help others too.
I'm using DirectAdmin and my cron examples are working both. I removed my email address from the 'Send all Cron output to E-Mail' so I don't receive email notifications of my cronjobs.
I started off with a cURL request which runs every 20 minutes:
*/20 * * * * /usr/local/bin/curl --silent 'https://demo.tld/app/stats/?update&key=1234'
Please note the ' ' around the URL, otherwise you can't add multiple parameters!
I use that page as an API inspired way to trigger the update of some statistics I collect from another website and which others can grab in JSON form from mine.
The parameter 'update' triggers the update process and the parameter 'key' will, when validated, trigger additional update actions I only want to be done when the cronjob requests the update.
Since above cronjob basically consumes bandwidth in both directions I wanted to go for a PHP based cronjob, but ran into a problem with the parameters... so that is when I found this post which saved my day :)
*/20 * * * * /usr/local/bin/php /home/path/to/public_html/app/stats/index.php update key=1234
As you can see the filename (index.php) is now included in the path and then the parameters follow (without the ? and &'s).
This way you get the cronjob working BUT you're only half way since the parameters won't be passed on via $_GET... which is a bit annoying when you've coded your script with checks for $_GET keys!
So, how does it work then? Simple (at least after some research), the cronjob passes the parameters to the script via a variable named $argv.
So with that knowledge I searched for a method to transform the $argv into $_GET so:
- I can trigger the update both manually and via the cronjob.
- I didn't had to rewrite my whole script.
I found the following solution which we only want to execute when $argv is actually set, so I wrapped it in the if isset check:
if( isset( $argv ) )
{
foreach( $argv as $arg ) {
$e = explode( '=', $arg );
if( count($e) == 2 )
$_GET[$e[0]] = $e[1];
else
$_GET[$e[0]] = 0;
}
}
Hope this helps you too :)