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();
}

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.