Doesn't run with url query
jamminjames opened this issue · 2 comments
Crunz version: x.y.z
2.2
PHP version: x.y.z
7.4
Operating system type and version:
Linux
Description
Is it possible to run a php script with a url query? Eg: $schedule->run('/usr/bin/php test_cron.php?iscron=1')
It doesn't seem to work. If not, is there any way to pass a variable to the php file, or for the php script to verify that it was triggered by a cron job via Crunz?
Is it possible to run a php script with a url query?
No, shells don't support that.
It doesn't seem to work. If not, is there any way to pass a variable to the php file, or for the php script to verify that it was triggered by a cron job via Crunz?
You can pass arguments to CLI like to any other binary, you can also enable error log.
Okay, gotcha. So for anyone looking at this, I did it this way:
$schedule->run('/usr/bin/php Z_test_cron.php --iscron=1')
...which works very similarly to a url query like test_cron.php?iscron=1
In the php file, read the passed argument like so:
$val = getopt(null, ["iscron:"]);
$val is now an array, so you can isolate the variable like so:
$iscron = $val["iscron"];