PHP options & information PHP options/info assert Checks if assertion is false Description int assert string|bool assertion assert will check the given assertion and take appropriate action if its result is false. If the assertion is given as a string it will be evaluated as PHP code by assert. The advantages of a string assertion are less overhead when assertion checking is off and messages containing the assertion expression when an assertion failes. Assertion should be used as a debugging feature only. You may use them for sanity-checks that test for conditions that should always be true and that indicate some programming errors if not or to check for the presence of certain features like extension functions or certain system limits and features. Assertions should not be used for normal runtime operations like input parameter checks. As a rule of thumb your code should always be able to work correct if assertion checking is not activated. The behavior of assert may be configured by assert_options or by .ini-settings described in that functions manual page. assert_options Set/get the various assert flags Description mixed assert_options int what mixed value Using assert_options you may set the various assert control options or just query their current settings. assert options option ini-parameter default description ASSERT_ACTIVE assert.active 1 enable assert evaluation ASSERT_WARNING assert.warning 1 issue a PHP warning for each failed assertion ASSERT_BAIL assert.bail 0 terminate execution on failed assertions ASSERT_QUIET_EVAL assert.quiet_eval 0 disable error_reporting during assertion expression evaluation ASSERT_CALLBACK assert_callback (null) user function to call on failed assertions
assert_options will return the original setting of any option or false on errors.
extension_loaded find out whether an extension is loaded Description bool extension_loaded string name Returns true if the extension identified by name is loaded. You can see the names of various extensions by using phpinfo. See also phpinfo. This function was added in 3.0.10. dl load a PHP extension at runtime Description int dl string library Loads the PHP extension defined in library. See also the extension_dir configuration directive. getenv Get the value of an environment variable Description string getenv string varname Returns the value of the environment variable varname, or false on an error. $ip = getenv ("REMOTE_ADDR"); // get the ip number of the user You can see a list of all the environmental variables by using phpinfo. You can find out what many of them mean by taking a look at the CGI specification, specifically the page on environmental variables. This function does not work in ISAPI mode. get_cfg_var Get the value of a PHP configuration option. Description string get_cfg_var string varname Returns the current value of the PHP configuration variable specified by varname, or false if an error occurs. It will not return configuration information set when the PHP was compiled, or read from an Apache configuration file (using the php3_configuration_option directives). To check whether the system is using a configuration file, try retrieving the value of the cfg_file_path configuration setting. If this is available, a configuration file is being used. get_current_user Get the name of the owner of the current PHP script. Description string get_current_user void Returns the name of the owner of the current PHP script. See also getmyuid, getmypid, getmyinode, and getlastmod. get_magic_quotes_gpc Get the current active configuration setting of magic quotes gpc. Description long get_magic_quotes_gpc void Returns the current active configuration setting of magic_quotes_gpc. (0 for off, 1 for on). See also get_magic_quotes_runtime, set_magic_quotes_runtime. get_magic_quotes_runtime Get the current active configuration setting of magic_quotes_runtime. Description long get_magic_quotes_runtime void Returns the current active configuration setting of magic_quotes_runtime. (0 for off, 1 for on). See also get_magic_quotes_gpc, set_magic_quotes_runtime. getlastmod Get time of last page modification. Description int getlastmod void Returns the time of the last modification of the current page. The value returned is a Unix timestamp, suitable for feeding to date. Returns false on error. getlastmod() example // outputs e.g. 'Last modified: March 04 1998 20:43:59.' echo "Last modified: ".date ("F d Y H:i:s.", getlastmod()); See alse date, getmyuid, get_current_user, getmyinode, and getmypid. getmyinode Get the inode of the current script. Description int getmyinode void Returns the current script's inode, or false on error. See also getmyuid, get_current_user, getmypid, and getlastmod. This function is not supported on Windows systems. getmypid Get PHP's process ID. Description int getmypid void Returns the current PHP process ID, or false on error. Process IDs are not unique, thus they are a weak entropy source. We recommend against relying on pids in security-dependent contexts. See also getmyuid, get_current_user, getmyinode, and getlastmod. getmyuid Get PHP script owner's UID. Description int getmyuid void Returns the user ID of the current script, or false on error. See also getmypid, get_current_user, getmyinode, and getlastmod. getrusage Get the current resource usages. Description array getrusage int who This is an interface to getrusage(2). It returns an associative array containing the data returned from the system call. If who is 1, getrusage will be called with RUSAGE_CHILDREN. All entries are accessible by using their documented field names. Getrusage Example $dat = getrusage(); echo $dat["ru_nswap"]; # number of swaps echo $dat["ru_majflt"]; # number of page faults echo $dat["ru_utime.tv_sec"]; # user time used (seconds) echo $dat["ru_utime.tv_usec"]; # user time used (microseconds) See your system's man page on getrusage(2) for more details. ini_alter Change the value of a configuration option Description string ini_alter string varname string newvalue Changes the value of a configuration option, returns false on failure, and the previous value of the configuration option on success. This is an alias of ini_set See also ini_get, ini_restore, ini_set ini_get Get the value of a configuration option Description string ini_get string varname Returns the value of the configuration option on success, false on failure. See also ini_alter, ini_restore, ini_set ini_restore Restore the value of a configuration option Description string ini_restore string varname Restores a given configuration option to its original value. See also ini_alter, ini_get, ini_set ini_set Set the value of a configuration option Description string ini_set string varname string newvalue Sets the value of the given configuration option. Returns the old value on success, false on failure. Not all the available options can be changed using ini_set. Below is a table with a list of all PHP options (as of PHP 4.0.5-dev), indicating which ones can be changed/set and at what level. Configuration options Name Default Changeable define_syslog_variables "0" PHP_INI_ALL highlight.bg HL_BG_COLOR PHP_INI_ALL highlight.comment HL_COMMENT_COLOR PHP_INI_ALL highlight.default HL_DEFAULT_COLOR PHP_INI_ALL highlight.html HL_HTML_COLOR PHP_INI_ALL highlight.keyword HL_KEYWORD_COLOR PHP_INI_ALL highlight.string HL_STRING_COLOR PHP_INI_ALL allow_call_time_pass_reference "1" PHP_INI_SYSTEM|PHP_INI_PERDIR asp_tags "0" PHP_INI_SYSTEM|PHP_INI_PERDIR display_errors "1" PHP_INI_ALL display_startup_errors "0" PHP_INI_ALL enable_dl "1" PHP_INI_SYSTEM error_append_string NULL PHP_INI_ALL error_prepend_string NULL PHP_INI_ALL expose_php "1" PHP_INI_SYSTEM html_errors "1" PHP_INI_SYSTEM ignore_user_abort "0" PHP_INI_ALL implicit_flush "0" PHP_INI_PERDIR|PHP_INI_SYSTEM log_errors "0" PHP_INI_ALL magic_quotes_gpc "1" PHP_INI_ALL magic_quotes_runtime "0" PHP_INI_ALL magic_quotes_sybase "0" PHP_INI_ALL output_buffering "0" PHP_INI_PERDIR|PHP_INI_SYSTEM output_handler NULL PHP_INI_PERDIR|PHP_INI_SYSTEM register_argc_argv "1" PHP_INI_ALL register_globals "1" PHP_INI_ALL safe_mode "0" PHP_INI_SYSTEM short_open_tag "1" PHP_INI_SYSTEM|PHP_INI_PERDIR sql.safe_mode "0" PHP_INI_SYSTEM track_errors "0" PHP_INI_ALL y2k_compliance "0" PHP_INI_ALL arg_separator "&" PHP_INI_ALL auto_append_file NULL PHP_INI_ALL auto_prepend_file NULL PHP_INI_ALL doc_root NULL PHP_INI_SYSTEM default_charset SAPI_DEFAULT_CHARSET PHP_INI_ALL default_mimetype SAPI_DEFAULT_MIMETYPE PHP_INI_ALL error_log NULL PHP_INI_ALL extension_dir PHP_EXTENSION_DIR PHP_INI_SYSTEM gpc_order "GPC" PHP_INI_ALL include_path PHP_INCLUDE_PATH PHP_INI_ALL max_execution_time "30" PHP_INI_ALL open_basedir NULL PHP_INI_SYSTEM safe_mode_exec_dir "1" PHP_INI_SYSTEM upload_max_filesize "2M" PHP_INI_ALL file_uploads "1" PHP_INI_ALL post_max_size "8M" PHP_INI_SYSTEM upload_tmp_dir NULL PHP_INI_SYSTEM user_dir NULL PHP_INI_SYSTEM variables_order NULL PHP_INI_ALL SMTP "localhost" PHP_INI_ALL browscap NULL PHP_INI_SYSTEM error_reporting NULL PHP_INI_ALL memory_limit "8M" PHP_INI_ALL precision "14" PHP_INI_ALL sendmail_from NULL PHP_INI_ALL sendmail_path DEFAULT_SENDMAIL_PATH PHP_INI_SYSTEM disable_functions "" PHP_INI_SYSTEM allow_url_fopen "1" PHP_INI_ALL
Definition of PHP_INI_* constants Constant Value Meaning PHP_INI_USER 1 Entry can be set in user scripts PHP_INI_PERDIR 2 Entry can be set in .htaccess PHP_INI_SYSTEM 4 Entry can be set in php.ini or httpd.conf PHP_INI_ALL 7 Entry can be set anywhere
See also ini_alter, ini_get, ini_restore
phpcredits Prints out the credits for PHP. Description void phpcredits int flag This function prints out the credits listing the PHP developers, modules, etc. It generates the appropriate HTML codes to insert the information in a page. A parameter indicating what will be printed (a pre-defined constant flag, see table below) needs to be passed. For example to print the general credits, you will use somewhere in your code: ... phpcredits(CREDITS_GENERAL); ... And if you want to print the core developers and the documentation group, in a page of its own, you will use: <?php phpcredits(CREDITS_GROUP + CREDITS_DOCS + CREDITS_FULLPAGE); ?> And if you feel like embedding all the credits in your page, then code like the one below will do it: <html> <head> <title>My credits page</title> </head> <body> <?php // some code of your own phpcredits(CREDITS_ALL + CREDITS_FULLPAGE); // some more code ?> </body> </html> Pre-defined <function>phpcredits</function> flags name description CREDITS_ALL All the credits, equivalent to using: CREDITS_DOCS + CREDITS_GENERAL + CREDITS_GROUP + CREDITS_MODULES + CREDITS_FULLPAGE. It generates a complete stand-alone HTML page with the appropriate tags. CREDITS_DOCS The credits for the documentation team CREDITS_FULLPAGE Usually used in combination with the other flags. Indicates that the a complete stand-alone HTML page needs to be printed including the information indicated by the other flags. CREDITS_GENERAL General credits: Language design and concept, PHP 4.0 authors and SAPI module. CREDITS_GROUP A list of the core developers CREDITS_MODULES A list of the extension modules for PHP, and their authors CREDITS_SAPI A list of the server API modules for PHP, and their authors
See also phpinfo, phpversion, php_logo_guid.
phpinfo Output lots of PHP information. Description int phpinfo int what Outputs a large amount of information about the current state of PHP. This includes information about PHP compilation options and extensions, the PHP version, server information and environment (if compiled as a module), the PHP environment, OS version information, paths, master and local values of configuration options, HTTP headers, and the PHP License. The output may be customized by passing one or more of the following values ored together in the optional parameter what. INFO_GENERAL INFO_CREDITS INFO_CONFIGURATION INFO_MODULES INFO_ENVIRONMENT INFO_VARIABLES INFO_LICENSE INFO_ALL See also phpversion, phpcredits, php_logo_guid phpversion Get the current PHP version. Description string phpversion void Returns a string containing the version of the currently running PHP parser. phpversion() example // prints e.g. 'Current PHP version: 3.0rel-dev' echo "Current PHP version: ".phpversion(); See also phpinfo, phpcredits, php_logo_guid, zend_version. php_logo_guid Get the logo guid Description string php_logo_guid void This funcionality was added in PHP 4 Beta 4. See also phpinfo. phpversion, phpcredits php_sapi_name Returns the type of interface between web server and PHP Description string php_sapi_name Php_sapi_name returns a lowercase string which describes the type of interface between web server and PHP (Server API, SAPI). In CGI PHP, this string is "cgi", in mod_php for Apache, this string is "apache" and so on. <function>Php_sapi_name</function> Example $sapi_type = php_sapi_name(); if ($sapi_type == "cgi") print "You are using CGI PHP\n"; else print "You are not using CGI PHP\n"; php_uname Returns information about the operating system PHP was built on Description string php_uname php_uname returns a string with a description of the operating system PHP is built on. <function>php_uname</function> Example if (substr(php_uname(), 0, 7) == "Windows") { die("Sorry, this script doesn't run on Windows.\n"); } putenv Set the value of an environment variable. Description void putenv string setting Adds setting to the server environment. Setting an Environment Variable putenv ("UNIQID=$uniqid"); set_magic_quotes_runtime Set the current active configuration setting of magic_quotes_runtime. Description long set_magic_quotes_runtime int new_setting Set the current active configuration setting of magic_quotes_runtime. (0 for off, 1 for on) See also get_magic_quotes_gpc, get_magic_quotes_runtime. set_time_limit limit the maximum execution time Description void set_time_limit int seconds Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the configuration file. If seconds is set to zero, no time limit is imposed. When called, set_time_limit restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out. Note that set_time_limit has no effect when PHP is running in safe mode. There is no workaround other than turning off safe mode or changing the time limit in the configuration file. zend_logo_guid Get the zend guid Description string zend_logo_guid void This funcionality was added in PHP 4 Beta 4. get_loaded_extensions Returns an array with the names of all modules compiled and loaded Description array get_loaded_extensions void This function returns the names of all the modules compiled and loaded in the PHP interpreter. For example the line below print_r (get_loaded_extensions()); will print a list like: Array ( [0] => xml [1] => wddx [2] => standard [3] => session [4] => posix [5] => pgsql [6] => pcre [7] => gd [8] => ftp [9] => db [10] => Calendar [11] => bcmath ) See also: get_extension_funcs. get_extension_funcs Returns an array with the names of the functions of a module Description array get_extension_funcs string module_name This function returns the names of all the functions defined in the module indicated by module_name. For example the lines below print_r (get_extension_funcs ("xml")); print_r (get_extension_funcs ("gd")); will print a list of the functions in the modules xml and gd respectively. See also: get_loaded_extensions get_required_files Returns an array with the names of the files require_once()'d or included_once()'d in a script Description array get_required_files void This function returns an array of the names of all the files that have been loaded into a script using require_once or include_once. In PHP 4.0.1pl2 this function assumed that the required_once files end in the extension ".php", other extensions do not work. Also, in that version the array returned was an associative array, and this function was not an alias for get_included_files As of PHP 4.0.4, this function is an alias for get_included_files See also: require_once, include_once, get_included_files get_included_files Returns an array with the names of the files include_once()'d in a script Description array get_included_files void This function returns an array of the names of all the files that have been loaded into a script using require_once or include_once. The example below Printing the required and included files <?php require_once ("local.php"); require_once ("../inc/global.php"); for ($i=1; $i<5; $i++) include "util".$i.".php"; echo "Required_once/Included_once files\n"; print_r (get_required_files()); will generate the following output: Required_once/Included_once files Array ( [0] => local.php [1] => /full/path/to/inc/global.php [2] => util1.php [3] => util2.php [4] => util3.php [5] => util4.php ) In PHP 4.0.1pl2 this function assumed that the include_once files end in the extension ".php", other extensions do not work. Also, in that version the array returned was an associative array, and listed only the included files. See also: require_once, include_once, get_required_files zend_version Get the version of the current Zend engine. Description string zend_version void Returns a string containing the version of the currently running PHP parser. <function>zend_version</function> example // prints e.g. 'Zend engine version: 1.0.4' echo "Zend engine version: ".zend_version(); See also phpinfo, phpcredits, php_logo_guid phpversion.