Was a Php Script Called From Command Line

Last modified: 
Tuesday, May 5th, 2015


How to tell if a PHP script was called from the command line.

  if (php_sapi_name() === 'cli' ) {
    print 'This script was called from the the command line.';
  else {
    print 'This script was NOT called from the command line.';

The operator of this site makes no claims, promises, or guarantees of the accuracy, completeness, originality, uniqueness, or even general adequacy of the contents herein and expressly disclaims liability for errors and omissions in the contents of this website.