PHP options & information
PHP options & information
error_log
Name
error_log — send an error message somewhere
Description
int error_log(string message, int message_type, string [destination], string
[extra_headers]);
Sends an error message to the web server's error log, a TCP port or to a file. The first parameter, message, is the error message that should be logged. The second parameter, message_type says where the message should go:
Table 1. error_log log types
0 |
message is sent to PHP's system logger, using the Operating System's system logging mechanism or a file, depending on what the error_log configuration directive is set to. |
---|---|
1 |
message is sent by email to the address in the destination parameter. This is the only message type where the fourth parameter, extra_headers is used. This message type uses the same internal function as Mail does. |
2 | message is sent through the PHP debugging connection. This option is only available if remote debugging has been enabled. In this case, the destination parameter specifies the host name or IP address and optionally, port number, of the socket receiving the debug information. |
3 |
message is appended to the file destination. |
Example 1. error_log examples
// Send notification through the server log if we can not
// connect to the database.
if (!Ora_Logon($username, $password)) { error_log("Oracle database not available!", 0);
}
// Notify administrator by email if we run out of FOO if (!($foo = allocate_new_foo()) {
error_log("Big trouble, we're all out of FOOs!", 1, "operator@mydomain.com");
}
// other ways of calling error_log():
error_log("You messed up!", 2, "127.0.0.1:7000"); error_log("You messed up!", 2, "loghost");
error_log("You messed up!", 3, "/var/tmp/my-errors.log");
error_reporting
Name
error_reporting — set which PHP errors are reported
Description
int error_reporting(int [level]);
Sets PHP's error reporting level and returns the old level. The error reporting level is a bitmask of the following values (follow the links for the internal values to get their meanings):
Table 1. error_reporting bit values
value | internal name |
---|---|
1 |
E_ERROR |
2 |
E_WARNING |
4 |
E_PARSE |
8 |
E_NOTICE |
16 |
E_CORE_ERROR |
32 |
E_CORE_WARNING |
getenv
Name
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.
get_cfg_var
Name
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.
get_current_user
Name
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.
getlastmod
Name
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.
Example 1. 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
Name
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.
getmypid
Name
getmypid — Get PHP's process ID.
Description
int getmypid(void);
Returns the current PHP process ID, or false on error.
Note that when running as a server module, separate invocations of the script are not guaranteed to have distinct pids.
See also getmyuid, get_current_user, getmyinode, and getlastmod.
getmyuid
Name
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.
phpinfo
Name
phpinfo — Output lots of PHP information.
Description
int phpinfo(void);
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 GNU Public License.
See also phpversion.
phpversion
Name
phpversion — Get the current PHP version.
Description
string phpversion(void);
Returns a string containing the version of the currently running PHP parser.
Example 1. phpversion() example
// prints e.g. 'Current PHP version: 3.0rel-dev' echo "Current PHP version: ".phpversion();
See also phpinfo.
putenv
Name
putenv — Set the value of an environment variable.
Description
void putenv(string setting);
Adds setting to the environment.
Example 1. Setting an Environment Variable
putenv("UNIQID=$uniqid");
set_time_limit
Name
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 php3.ini. 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.