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)

<?php
$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
http://php.net/security.cgi-bin for your options. Read
http://httpd.apache.org/docs/howto/cgi.html.html also for the
fundamentals.

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

C:\>myscript.php

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
php.exe.


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:

http://www.php.net/manual/en/features.commandline.php

To dynamically change your php.ini values, see
http://www.php.net/manual/en/function.ini-set.php. Example use:

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

No comments: