How to Change the PHP Resource Limitation Variables

The configuration file (php.ini) is read when PHP starts up. For the server module versions of PHP, this happens only once when the web server is started. A critical file you often need to manage is the php.ini file. It controls many import aspects of what you can and can not do with your site, including the size of files that you can upload or Maximum execution time and Memory limit.

The First Step: How to Find the Location of php.ini File

Different hosts use different methods for storing and accessing files and so you need to research where your php.ini file. One of the easiest methods is to display the PHP information of the Server or Host.

For this job You need to create a very simple php script and place it in your home directory. Using a script editor or a plain text editor (not a word processor) create file called phpinfo.php with this code:

<?php phpinfo(); ?>

That’s all you need. Just one single line. Save the file and call it phpinfo.php.

Upload this file to the public_html directory or whatever your main HTML directory is called.

In your browser address bar, access the file by typing in: or http://localhost/phpinfo.php

You get a complete list of all your php settings. Which includes the location of the php.ini file.

php loaded configuration file

Note : On some servers you do not have permission to change the values of php.ini file. In these cases you must make these changes through .htaccess file or PHP Code or wordpress wp-config.php file.

Method 1: How to Change PHP maximum execution time

Max_Execution_Time, defines the maximum time a script can run. By default, this is set to 30 seconds. If a script runs for longer than 30 seconds, it is automatically stopped and an error is reported.

You may wish to extend this time limit, if you need to run large scripts on your server. Typically, PHP scripts (in WordPress plugins and themes, for example) will mention whether you need to increase the maximum execution time in their documentation.

For change Max_Execution_Time in php.ini file, first find this keyword “max_execution_time” and use the following setting:

max_execution_time = 60

If you do not have access to the php.ini, use the following code in the .htaccess file on root of host (Public_HTML):

php_value max_execution_time 60

If you are using WordPress, you can do use the following Code in the WordPress WP-Config.php file:

define('MAX_EXECUTION_TIME', '60');

Finally, Do this through with PHP Code. use the following code top of all PHP Code:

ini_set('max_execution_time', 60);

Note: If the above methods did not work, Usually Hosts control panel (Cpanel, WHM, Xampp, etc) Provides Options for allow users to change the values of php.ini file.

Method 2: How to Change the PHP Upload File Size

By default, PHP allows uploading maximum 2 MB file on the server. But you can change the maximum size of file upload as per your requirement. Using the PHP configuration file (php.ini), you can increase or decrease the file upload size in PHP. The upload_max_filesize and post_max_size variable’s value need to be modified.

php.ini :

upload_max_filesize = 128M
post_max_size = 128M

.htaccess :

php_value upload_max_filesize 128M 
php_value post_max_size 128M

WordPress wp-config.php :

define('UPLOAD_MAX_FILESIZE', '128M');
define('POST_MAX_SIZE', '128M');

PHP Code :

ini_set('upload_max_filesize', 128M);
ini_set('post_max_size', 128M);

Method 3: How to Change the PHP Memory Limit

This sets the maximum amount of memory in bytes that a script is allowed to allocate. This helps prevent poorly written scripts for eating up all available memory on a server. Note that to have no memory limit, set this directive to -1.


memory_limit = 256M


php_value memory_limit 256M

WordPress wp-config.php :

define( 'WP_MEMORY_LIMIT', '256M' );

PHP Code:


Method 4: How to change the maximum number of input variables for PHP scripts

The PHP Max Input Vars is the maximum number of variables your server can use for a single function. By default, the maximum number of input variables allowed for PHP scripts is set to 1000.


max_input_vars = 2000


php_value max_input_vars 2000

WordPress wp-config.php :

define( 'MAX_INPUT_VARS', '2000' );

PHP Code:


Finally This list includes the php.ini directives you can set to configure your PHP setup.