title: How to distinguish command-line and web-server invocation?
body: <p>Is there a way to distinguish if a script was invoked from the command line or by the web server? </p>
  
  <p>(<strong>See <a href="https://stackoverflow.com/questions/173851/what-is-the-canonical-way-to-determine-commandline-vs-http-execution-of-a-php-s">What is the canonical way to determine commandline vs. http execution of a PHP script?</a> for best answer</strong> and more detailed discussion - didn't find that one before posting)</p>
  
  <hr>
  
  <p>I have a (non-production) server with Apache 2.2.10 and PHP 5.2.6. On it, in a web-accessible directory is my PHP script, <code>maintenance_tasks.php</code>. I would like to invoke this script from the command line or through a HTTP request (by opening in a browser). Is there some variable that allows me to reliably determine how script is invoked?</p>
  
  <p>(I already tackled the issues of different views for each type of invocation and HTTP response timeout, just looking for a way of telling the two invocation types apart)</p>
  
  <p>I'll be trying different things and add my findings below.</p>
  
  <p><strong>Duplicate:</strong> <a href="https://stackoverflow.com/questions/173851/what-is-the-canonical-way-to-determine-commandline-vs-http-execution-of-a-php-s">What is the canonical way to determine commandline vs. http execution of a PHP script?</a></p>