I have a PHP file that is needed to be run from command line (via crontab). I need to pass type=daily
to the file but I don't know how. I tried:
php myfile.php?type=daily
but this error was returned:
Could not open input file: myfile.php?type=daily
What can I do?
This code should not be used. First of all CLI called like: /usr/bin/php phpscript.php will have one argv value which is name of script
This one will always execute since will have 1 or 2 args passe
To use $_GET so you dont need to support both if it could be used from command line and from web browser.
Using getopt() function we can also read parameter from command line just pass value with php running command
php abc.php --name=xyz
abc.php
$val = getopt(null, ["name:"]);
print_r($val);
o/p:-
array ( 'name' => 'xyz', )
I put parameters in $_REQUEST
and also usable directly
use this like that:
parameters send by index like other application
and then you can gat them like this
I strongly recommend the use of getopt.
Documentation at http://php.net/manual/en/function.getopt.php
If you wanna the help print out for your options than take a look at https://github.com/c9s/GetOptionKit#general-command-interface