When I added some additional functionality to my php script, that should only manifest when the cron runs, the script stopped working. Is it not possible to put variables into the URL that the cron executes? Here is my example:
The “?” and “&” are characters which have a special meaning to the Linux shell. Try putting the whole command in single-quotes: ‘/home3/… …method=cron’
The “>/dev/null” says "take the console output from this command and dump it in the trash. “2>&1” says “do the same with error messages”.
What is more common, and probably safer, in a cron job is to re-direct the console output like this: >>/some-directory-path/some-file.log 2>&1
That puts everything into a file, so if the job fails, you have a place to look for messages that may point the way to a solution. Starting with “>>” instead of “>” means that every time you run the job, it will attach the output to the end of the file, instead of writing over it from the beginning.
To answer the question as to why you can’t call your scripts like this, when you run a PHP script from a web browser with a URL, the part after the ? (the query string) has key=value pairs separated by &s, which become the $_GET super global in PHP.
When you are running a php script via a cron task, it’s the same as if you were running it from a command line/shell, and so you can use a query string like you would in a URL. It’s possible to pass arguments to a PHP script (as you would to a shell script) and they would be contained in the argv array. Assuming your PHP script can handle command-line arguments (or can be modified by you or someone else to use them) then you can still pass arguments via cron, just in a different format.