note 93970 deleted from function.php-sapi-name by danbrown

From: Date: Tue, 13 Oct 2009 15:48:59 +0000
Subject: note 93970 deleted from function.php-sapi-name by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-161697@lists.php.net to get a copy of this message
Note Submitter: clancy hood at gmail dot com ---- good call by michal at roszka dot pl: <?php define('PHP_CXT_HTTP', 1); define('PHP_CXT_TERM', 2); define('PHP_CXT_CLI', 4); define('PHP_CXT_CGI', 8); define('PHP_CXT_MOD', 16); $X = isset($argc) ? PHP_CXT_TERM : PHP_CXT_HTTP; switch(substr(PHP_SAPI, 0, 3)){ case 'cgi': $X = $X | PHP_CXT_CGI; break; case 'cli': $X = $X | PHP_CXT_CLI; break; default: $X = $X | PHP_CXT_MOD; } define('PHP_CXT', $X); echo 'This script was '.(PHP_CXT & PHP_CXT_HTTP ? '' : 'not ')."initiated via a HTTP request <br/>\n"; echo 'This script was '.(PHP_CXT & PHP_CXT_TERM ? '' : 'not ')."initiated via a terminal <br/>\n"; echo 'PHP is '.(PHP_CXT & PHP_CXT_CGI ? '' : 'not ')."running as CGI <br/>\n"; echo 'PHP is '.(PHP_CXT & PHP_CXT_CLI ? '' : 'not ')."running as CLI <br/>\n"; echo 'PHP is '.(PHP_CXT & PHP_CXT_MOD ? '' : 'not ')."running as a server module <br/>\n"; ?> Tested via http and cmdline on own box (cli) and remote cgi-only host. However, isset($argc) is a very weak test, and this need be called at the very beginning of a script tree. If anyone has a better method of orientating oneself in an arbitrary environment *please do* correct me.

« previous php.notes (#161697) next »