To detect if your PHP script is being called via a web client or via CLI, you can use the php_sapi_name() function. If I use this simple code:

echo php_sapi_name();

Then from a web browser you will see: cgi-fcgi and from CLI you will see cli.

Leave a Reply

Your email address will not be published. Required fields are marked *