How to Read Individual PHP Configuration Settings


In this article, we show how to read individual PHP configuration settings.

Although we can see all the settings of PHP for a given server through the phpinfo() method, for many applications it is overdoing it if all we want is to access one setting. That's not even the larger issue. A given script may operate differently based on a certain setting. So if you're writing a script that behaves one way if a setting is enabled and another way if it is disabled, then you need to be able to read the value of the setting in a script. This is why in this case, phpinfo() is of no use.

PHP has a function for checking PHP configuration settings. This is the ini_get() function.

Inside of this function, you pass in the specific configuration setting that you want to read.

So to get the value of the memory_limit configuration setting, the following code below will get it.

Actual PHP Output

The memory limit of this script is 128M

So you can see that we've read the PHP configuration, memory_limit above. The maximum memory that a PHP script can be on this server is 64MB (a very large value for a PHP script).

And, of course, you can apply the PHP ini_get() function to any numerous other configuration settings.

The configuration setting, max_execution_time, is the maximum time that a PHP script can take to be processed by the server.

The configuration setting, upload_max_filesize, is the maximum file size that can be uploaded to the server with a PHP script.

So if I ran the PHP ini_get function wtih the max_execution_time and upload_max_filesize configuration settings, I would get the following code below.

Actual PHP Output

Maximum execution time is 30
Maximum file upload size is 32M

Related Resources

How to Set Individual PHP Configuration Settings

HTML Comment Box is loading comments...