Run PHP script only on command line

Snippet

In case a PHP script should be run only on the command line, and not in a browser

if (php_sapi_name() != 'cli') {
  /* do any clean up or logging here */
  exit();
}