Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 6311936 bytes)

The error you're encountering, "Allowed memory size of 268435456 bytes exhausted," indicates that your PHP script is trying to allocate more memory than is allowed by the server's configuration.

Here’s how you can resolve this issue:

Option 1: Increase Memory Limit via PHP Script

You can try increasing the memory limit within your PHP script by adding the following line at the beginning of your script:

ini_set('memory_limit', '512M'); // You can adjust the value as needed


This will temporarily increase the memory limit for that specific script.

Option 2: Increase Memory Limit in `php.ini`

If you have access to your `php.ini` file, you can increase the memory limit globally:

1. Open your `php.ini` file.
2. Search for the `memory_limit` directive.
3. Change it to a higher value, such as:

memory_limit = 512M

4. Save the changes and restart your web server (e.g., Apache or Nginx).

Option 3: Increase Memory Limit via `.htaccess`

If you don’t have access to the `php.ini` file, you can try increasing the memory limit through the `.htaccess` file:

1. Open your `.htaccess` file.
2. Add the following line:

php_value memory_limit 512M

Option 4: Optimize Your Code

If increasing the memory limit doesn't solve the issue or you cannot change the memory limit, it might be worth looking into your code to optimize memory usage. For example:

- Unset unused variables.
- Use `unset()` for large arrays or objects when they are no longer needed.
- Consider processing data in smaller chunks if dealing with large datasets.

Option 5: Contact Hosting Provider

If you're on shared hosting and can't modify these settings, you might need to contact your hosting provider to increase the memory limit.

If you need further assistance, Please feel free to ask!

  • fatal error, memory size, memory limit, php.ini
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to install AVG Antivirus scanner on Ubuntu?

AVG free is antivirus which protects from spyware as well malware. It is free to use for private...

How to setup a WordPress website on plain Centos server?

The following steps have been successfully tested on a plain centos server. Now lets start...

How to change the port number of Apache Web Server?

Default port to access the Apache is 80. Secure port for communicating with world for Apache is...

How to install Postfix on CentOS?

Postfix is an open-source Mail Transport Agent (MTA), which supports protocols like LDAP, SMTP...

How to install SOAP on CentOS?

Install SOAP on CentOS 1) Fire below command - yum install php-soap Output will be as follow...

Powered by WHMCompleteSolution