Command Line vs. Web PHP
Nugget posted by Mark Fenoglio
November 15, 2009

In many environments, session_start() is either meaningless or will generate permission errors for PHP scripts being executed from the command line. Fortunately, the $_SERVER global variable contains data that make it possible to differentiate where a PHP script is being run:

if (! isset($_SERVER['SHELL'])) session_start();

Now, only when the particular script is being run outside a shell environment will a session_start() be attempted.