Thursday, June 4, 2009

find out which mode php is running CGI or DSO mode (dynamically shared objects) (Apache module)

find out which mode php is running CGI or DSO mode (dynamically shared objects) (Apache module)

$sapi_type = php_sapi_name();
if (substr($sapi_type, 0, 3) == 'cgi') {
echo "You are using CGI PHP\n";
} else {
echo "You are not using CGI PHP\n";

// Note: An alternative approach
// The PHP constant PHP_SAPI has the same value as php_sapi_name().

You can have both a CGI (i.e. standalone) PHP executable and mod_php on
the same system. The mod_php module will be used for web serving of
your PHP scripts if this module is loaded by your httpd configuration.

To set up your web server and php.ini for CGI execution of PHP scripts
via the web, you'll need to do more than create a PHP binary. Read for your options. Read also for the

To execute a PHP script on a win32 system, just cd to the dir that the
script is in and type the script name:


Note, however, that if the script is a form that posts back to itself,
the only thing you will get is the form elements echoed to the console.
You will have to hardcode the form field values first if you want to
see the post in action.

Also, the .php extension should be registered to be executed with

To pass an argument to a cgi php script, e.g.,

# /tmp/test.php -f

use the $argv array, as in C:

if ($argv[1]=="-f") {
echo "The first argument is -f.\n";

Again, be sure to read the manual page for more information (and
examples) on using PHP from the commandline:

To dynamically change your php.ini values, see Example use:

echo "include_path=",ini_get("include_path"),"\n";
echo "include_path=",ini_get("include_path"),"\n";
include "test.php"; // Infinite loop if this code is run from

No comments: