-1
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?

Jean-François Corbett
  • 36,032
  • 27
  • 135
  • 183
NoNameZ
  • 775
  • 3
  • 13
  • 22

2 Answers2

1

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';
}
Community
  • 1
  • 1
Jorge Fuentes González
  • 10,984
  • 4
  • 40
  • 62
0

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']);
}
user268396
  • 11,028
  • 28
  • 26