Pass Parameters In Cron URL - PHP

How to pass parameters to file path? This is what I’m trying to do:

*/2 * * * * /usr/bin/php /var/www/mysite/public_html/cron/cron.php?group=3 >> /var/www/mysite/public_html/cron/cron.log 2>&1

I also tried without the question mark ‘?’ but the cron does not run.

*/2 * * * * /usr/bin/php /var/www/mysite/public_html/cron/cron.php?group=3 >> /var/www/mysite/public_html/cron/cron.log 2>&1

To to pass the parameter?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

As the file is inside the public_html directory you can also use curl to issue a HTTP request via URL:

*/2 * * * * curl -s >> /var/www/mysite/public_html/cron/cron.log 2>&1

Generally you would not use this method to pass parameters to a CLI PHP script. Instead you would do something like:

*/2 * * * * /usr/bin/php /var/www/mysite/public_html/cron/cron.php 3 >> /var/www/mysite/public_html/cron/cron.log 2>&1

Using $argv[0] to get the value inside your script.