Get current PHP API

One method to know if the script being executed has been started through cli, apache or any other API is to use PHP_SAPI:

if (PHP_SAPI != ‘cli’) { … }

will ensure that the script is executed in a command-line context before doing what’s inside the brackets.

Related Posts

Language detection in PHP

This is a *very* short note, but I’m writing it down in case...

PclZip and gzopen64()

I have updated my system early to Ubuntu 9.10 (Karmic Koala) and, to...