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.
I tried using if (php_sapi_name() == 'cli') {
but that tests true even if the script is being included in another script that was called from the command line.