php -f script.php param1 param2
At the moment, I am just checking whether isset($argv)
. Is this the best way?
P.S.
I also wanted to know if all input parameters are always stored in $argv
?
php -f script.php param1 param2
At the moment, I am just checking whether isset($argv)
. Is this the best way?
P.S.
I also wanted to know if all input parameters are always stored in $argv
?
As you can read here Is there any way to know if a php script is running in cli mode? you can use this function:
function is_cli()
{
return php_sapi_name() === 'cli';
}
Check whether or not a REQUEST_METHOD
is set:
/**
* Check if the site is being visited (in a browser) or run as a program from the
* commandline.
* @return boolean true if the request appears to come from the WWW, false if not.
*/
function is_web_request () {
return isset($_SERVER['REQUEST_METHOD']);
}