PHP : check whether script running from cli or with apache

June 13th, 2015 § 0 comments

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 php_sapi_name() method.

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.

Revath S Kumar [RSK]

- Rubyist / JavaScripter - Yeoman Team member - Open source enthusiast - Blogger @ PHPRepo and - Coder @ Whatznear - Google fanboy - jQuery lover

More Posts - Website - Twitter - Facebook - LinkedIn - Pinterest - Google Plus - YouTube

Comments are closed.