Recently I was in need of some way to identity the script is running from command line or using apache server. Then I came to know about
The php_sapi_name method will return the type of interface. for command line it will return cli.
If the script is running with apache, it will return different values according to its Server API. when I tried to run my script with apache it returned apache2handler.