Skip to content

How you can Increase PHP Memory Limit and Upload File Limit and Script Execution Time

A PHP memory limit of 16MB is placed automatically in PHP. Some sites may require greater than 32MB. Memory limits of 64MB and greater aren’t unusual. Default upload file limit is 2MB is very low, particularly if site works together with photos which could easily convey more then 32MB size. For Script Execution time – it’s set to thirty seconds automatically however, many tasks (for instance service cron tasks) require more time for you to finish their job. There are many strategies to boost the PHP memory limit, upload file limit and execution time – you simply need to use one of these. The best for you depends upon the body configuration.

1. Set Memory Limit

1.1. php.ini configuration

This is actually the suggested approach if you can get the server’s php.ini. This won’t be possible in many shared web hosting environments, though your host might be able to adjust it for you personally. Observe that this transformation will affect all websites and PHP scripts around the server.

– Locate the php.ini file utilized by your internet server. You should use the phpinfo() PHP function to locate it.

– Edit the memory_limit parameter within the php.ini file (usually inside a section known as Resource Limits)

memory_limit = 32M Maximum quantity of memory a script may consume (32MB)

If there’s no section already with this, put the above line in the finish from the file.

– Restart Apache.

Note: If you work with XAMPP/WAMP, there might be two PHP.ini files (one underneath the PHP directory and yet another under Apache/bin). To modify your memory limit, edit the file within the XAMPP/Apache/bin directory.

The following two solutions tend to be more restricted in scope and, in some instances, might be appropriate choices than affecting all sites.

1.2. .htaccess configutaion

This really is helpful when you don’t have use of php.ini file.

Edit (Create) the .htaccess file within the site root (public) directory and add some following line:

php_value memory_limit 32M

This process is only going to work if PHP is running being an Apache module.

1.3. Configuration in PHP scripts

Add some following line where you have to give PHP more memory:

ini_set(‘memory_limit’, ’32M’)

1.4. Memory limits on Shared Hostings.

In certain shared web hosting environments, accessibility PHP memory limit setting is fixed. If you fail to result in the change yourself, please ask your host company to regulate it for you personally, or locate a new host that enables more versatility.

2. Set Upload Quality Limit

Your php installation putting limits on upload quality. The default will restrict you to definitely a max 2 MB upload quality. You have to set the next three configuration options:

– upload_max_filesize – The utmost size an submitted file.

– memory_limit – This sets all the memory in bytes that the script is permitted to allocate. This can help prevent poorly written scripts for eating up all available memory on the server. Observe that to possess no memory limit, set this directive to -1.

– publish_max_size – Sets max size publish data permitted. This setting may also affect file upload. To upload large files, this value should be bigger than upload_max_filesize. If memory limit is enabled from your configure script, memory_limit may also affect file uploading. In most cases, memory_limit ought to be bigger than publish_max_size.

There’s two methods two fix this issue.

2.1. php.ini configuration

– Locate the php.ini file utilized by your internet server. You should use the phpinfo() PHP function to locate it.

– find and modify next parameters:

memory_limit = 32M

upload_max_filesize = 10M

publish_max_size = 20M

– restart Apache

2.2. .htaccess configuration

This really is helpful when you don’t have use of php.ini file.

Edit (Create) the .htaccess file within the site root (public) directory and add some following line:

php_value upload_max_filesize 10M

php_value publish_max_size 20M

php_value memory_limit 32M

This process is only going to work if PHP is running being an Apache module.

3. Increase Script Execution Time

PHP scripts are just permitted to become performed for any certain time period, so when it reaches time limit, it’ll stop and convey the next error:

“Fatal error: Maximum execution duration of thirty seconds exceeded in yourscript.php”

To permit your PHP script to operate at a longer period, you will need to boost the maximum execution time period limit of PHP scripts using the following methods.

3.1. php.ini configuration

– Locate the php.ini file utilized by your internet server. You should use the phpinfo() PHP function to locate it.

– find and modify next parameter:

max_execution_time = 45

Alter the value (in second) or set to for infinite time

– restart Apache

3.2. .htaccess configuration

Edit (Create) the .htaccess file within the site root (public) directory or perhaps in your directory of the script and add some following line:

php_value max_execution_time 45

Alter the value (in second) or set to for infinite time

3.3. Configuration in PHP scripts

This really is most likely the best way because the setting applies simply to the specific script, and wouldn’t allow other poorly written scripts also to consume and waste the system’s resource.

To get this done, call the next function inside your PHP script using the maximum execution amount of time in second because the parameter:

set_time_limit ( 300 )

You should use as parameter for infinite execution time.