Search code examples
phpruntimewebservercommand-line-interfacemode

Which method to detect run mode of php script is more reliable?


I now to ways to detect weather php script runs in cli or web server mode:

if (defined('STDIN'))

or:

if (isset($argc))

Do they equally reliable or one of them is more ?


Solution

  • Neither. Check the value returned from php_sapi_name().