PHP options & informationPHP options/infoassertChecks if assertion is falseDescriptionint assertstring|bool assertionassert 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_optionsSet/get the various assert flagsDescriptionmixed assert_optionsint whatmixed
value
Using assert_options you may set the various
assert control options or just query their
current settings.
assert optionsoptionini-parameterdefaultdescriptionASSERT_ACTIVEassert.active1enable assert evaluationASSERT_WARNINGassert.warning1issue a PHP warning for each failed assertionASSERT_BAILassert.bail0terminate execution on failed assertionsASSERT_QUIET_EVALassert.quiet_eval0
disable error_reporting during assertion expression
evaluation
ASSERT_CALLBACKassert_callback(null)user function to call on failed assertions
assert_options will return the original
setting of any option or false on errors.
extension_loadedfind out whether an extension is loadedDescriptionbool extension_loadedstring 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.
dlload a PHP extension at runtimeDescriptionint dlstring library
Loads the PHP extension defined in
library. See also the extension_dir configuration
directive.
getenvGet the value of an environment variableDescriptionstring getenvstring 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.
Descriptionstring get_cfg_varstring 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.
Descriptionstring get_current_uservoid
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.
Descriptionlong get_magic_quotes_gpcvoid
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.
Descriptionlong
get_magic_quotes_runtimevoid
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.
getlastmodGet time of last page modification.Descriptionint getlastmodvoid
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.
getmyinodeGet the inode of the current script.Descriptionint getmyinodevoid
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.
getmypidGet PHP's process ID.Descriptionint getmypidvoid
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.
getmyuidGet PHP script owner's UID.Descriptionint getmyuidvoid
Returns the user ID of the current script, or false on error.
See also getmypid,
get_current_user,
getmyinode, and
getlastmod.
getrusageGet the current resource usages.Descriptionarray getrusageint
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_alterChange the value of a configuration optionDescriptionstring ini_alterstring varnamestring 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_setini_getGet the value of a configuration optionDescriptionstring ini_getstring varname
Returns the value of the configuration option on success,
false on failure.
See also ini_alter,
ini_restore,
ini_setini_restoreRestore the value of a configuration optionDescriptionstring ini_restorestring varname
Restores a given configuration option to its original value.
See also ini_alter,
ini_get,
ini_setini_setSet the value of a configuration optionDescriptionstring ini_setstring varnamestring 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.
Definition of PHP_INI_* constantsConstantValueMeaningPHP_INI_USER1Entry can be set in user scriptsPHP_INI_PERDIR2Entry can be set in .htaccessPHP_INI_SYSTEM4Entry can be set in php.ini or
httpd.confPHP_INI_ALL7Entry can be set anywhere
See also ini_alter,
ini_get,
ini_restorephpcreditsPrints out the credits for PHP.Descriptionvoid phpcreditsint 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 phpcredits flagsnamedescriptionCREDITS_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_DOCSThe credits for the documentation teamCREDITS_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_GROUPA list of the core developersCREDITS_MODULESA list of the extension modules for PHP, and their authorsCREDITS_SAPIA list of the server API modules for PHP, and their authors
See also phpinfo,
phpversion,
php_logo_guid.
phpinfoOutput lots of PHP information.Descriptionint phpinfoint 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_GENERALINFO_CREDITSINFO_CONFIGURATIONINFO_MODULESINFO_ENVIRONMENTINFO_VARIABLESINFO_LICENSEINFO_ALL
See also phpversion,
phpcredits,
php_logo_guidphpversionGet the current PHP version.Descriptionstring phpversionvoid
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_guidGet the logo guidDescriptionstring php_logo_guidvoid
This funcionality was added in PHP 4 Beta 4.
See also phpinfo.
phpversion,
phpcreditsphp_sapi_name
Returns the type of interface between web server and PHP
Descriptionstring php_sapi_namePhp_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.
Php_sapi_name 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
Descriptionstring php_unamephp_uname returns a string with a description
of the operating system PHP is built on.
php_uname Example
if (substr(php_uname(), 0, 7) == "Windows") {
die("Sorry, this script doesn't run on Windows.\n");
}
putenvSet the value of an environment variable.Descriptionvoid putenvstring 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.
Descriptionlong
set_magic_quotes_runtimeint 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_limitlimit the maximum execution timeDescriptionvoid set_time_limitint 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_guidGet the zend guidDescriptionstring zend_logo_guidvoid
This funcionality was added in PHP 4 Beta 4.
get_loaded_extensions
Returns an array with the names of all modules compiled and
loaded
Descriptionarray get_loaded_extensionsvoid
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
Descriptionarray get_extension_funcsstring 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_extensionsget_required_files
Returns an array with the names of the files require_once()'d or
included_once()'d in a script
Descriptionarray get_required_filesvoid
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_filesget_included_files
Returns an array with the names of the files include_once()'d in
a script
Descriptionarray get_included_filesvoid
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_fileszend_versionGet the version of the current Zend engine.Descriptionstring zend_versionvoid
Returns a string containing the version of the currently running
PHP parser.
zend_version example
// prints e.g. 'Zend engine version: 1.0.4'
echo "Zend engine version: ".zend_version();
See also phpinfo,
phpcredits,
php_logo_guidphpversion.