Configuration PHP

The following functions affect the operation of PHP. Some of them alter configuration variables. Others cause a script to stop executing for a period of time.

boolean bcscale(integer scale)
The bcscale function sets the default scale for the functions that perform math on arbitrary-precision numbers. The scale is the number of digits after the decimal point.

//use ten digits

Calling C's stat function may take a considerable amount of time. To increase performance, PHP caches the results of each call. When you use a function that relies on stat, the information from the cache is returned. If information about a file changes often, you may need to clear the stat cache. The functions that use the stat cache are: stat, file_exists, fileatime, filectime, fileinode, filegroup, fileowner, fileperms, filesize, filetype.

//make sure info isn't cached
//get size of this file

The define_syslog_variables function emulates the configuration directive of the same name. It causes the constants for use with the system log to be created as variables. The functions that interact with the system log are closelog, openlog, and syslog.


boolean dl(string extension)
Use the dl function to load a dynamic extension module. The function returns FALSE if the module could not be loaded. The path to these modules is set in php.ini, so you need type only the name of the module file.

//load windows mysql module
//show diagnostics

integer error_reporting(integer level)
The error_reporting function sets the level of error reporting and returns the previous value. The level argument is a bitfield, so use the bitwise OR operator (|) to put together the type of error reporting you would like. By default PHP uses a level of seven, which is Errors, Warnings, and Parser Errors.

integer error_reporting(integer level)integer error_reporting(integer level)

boolean ignore_user_abort(boolean ignore)
Calling ignore_user_abort with a TRUE value for the ignore argument will cause PHP to continue executing even when the remote client abruptly closes the connection. The previous setting is returned. You may call ignore_user_abort with no argument, in which case no change is made.

function fakeProcess($name)
print("Start of fake process.<BR>n");
print("End of fake process.<BR>n");
//write message to log
$statusMessage = date("Y-m-d H:i:s") . " Fake
process $name completedn";
error_log($statusMessage, 3, "status.log");
//finish script even if user
//aborts execution
//allow aborts again

string ini_alter(string directive, string value)
Use ini_alter to override the value of one of the directives in the php.ini file. The setting is for your script only. The file itself is not changed.

string ini_get(string directive)
The ini_get function returns the value of one of the directives in the php.ini file.

//see what SMTP is now
print(ini_get("SMTP") . "<BR>n");
//change to bogus value
ini_alter("SMTP", "");
print(ini_get("SMTP") . "<BR>n");
//return to original
print(ini_get("SMTP") . "<BR>n");

ini_restore(string directive)
The ini_restore function returns the named directive to the value in the php.ini file. See ini_get for an example of use.

You may use magic_quotes_runtime as an alias to set_magic_quotes_ runtime.

register_shutdown_function(string function)
Use register_shutdown_function to cause PHP to execute a function after it has parsed the entire script, including anything outside PHP tags. The shutdown function will also be executed in the event of an error, timeout, or user abort. Keep in mind that the shutdown function may be called after the connection to the browser has been shut down, in which case using print makes little sense. In other words, this isn't a good way to debug. You may register more than one shutdown function. Each will be executed in the order they were registered.

function shutdown()
print("!-- Script Terminated -->n");

integer set_magic_quotes_runtime(boolean setting)
Use set_magic_quotes_runtime to change whether quotes are escaped in data pulled from a database. The original value is returned.
//turn off magic_quotes_runtime

string setlocale(string category, string locale)
The setlocale function modifies the locale information for PHP and returns the new locale specification. FALSE is returned if an error occurs. The locale determines things such as whether to use a comma or a period in floating-point numbers. Locale does not affect how you write PHP scripts, only the output of some functions.

If the category argument is an empty string, the values for the categories will be set from environment variables. If the category argument is zero, the current setting will be returned.

This function wraps the C function of the same name, so it's a good idea to check out the man page. PHP accepts some categories that have no effect on PHP itself. Also, PHP does not necessarily accept all the valid categories your operating system offers.

Location codes differ with operation systems. In general they take the form of language_country—that is, a language code followed by an optional underscore and a country code. If you are using Windows, Visual C's help file lists all the languages and countries.

// change locale in Windows NT
print("Changing to Russian: ");
print(setlocale(LC_ALL, "russian"));
print("Dos vedanya!"); ?>

Set_time_limit(integer seconds)
Use set_time_limit to override the default time a script is allowed to run, which is usually set to 30 seconds inside php.ini. If this limit is reached, an error occurs and the script stops executing. Setting the seconds argument to zero causes the time limit to be disabled. Each time the set_time_limit function is called, the counter is reset to zero. This means that calling set_time_limit (30) gives you a fresh 30 seconds of execution time. The time-limit functionality does not operate in Windows. Scripts will execute until finished.

// allow this script to run forever

sleep(integer seconds)
The sleep function causes execution to pause for the given number of seconds.


usleep(integer microseconds)
The usleep function causes execution to pause for the given number of microseconds. There are a million microseconds in a second.


Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

PHP Topics