title: PHP script detect that it is an include
body: <p>I have a PHP class file that is used as an include both through a web server and by a cron process. I am looking for a way to add some code to the head of the script so that I can detect if the script is being launched directly from the command line instead of being included in another script. This way I can make testing a bit easier by calling the script directly and having a function instantiate the object and execute some code on it without needing to create a wrapper script for it.</p>
  
  <p>I tried using <code>if (php_sapi_name() == 'cli') {</code> but that tests true even if the script is being included in another script that was called from the command line.</p>