Simon
Simon

Reputation: 45

PHP fatal error: Allowed memory size exhausted. How to fix?

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to
allocate 24 bytes)
in /home/fevsdiet/public_html/xxxxxxx.co.uk/booking/includes/functions.php
on line 481

What does this mean and how would one go about fixing it?

This is the code that is erroring:

   $availabilityArr = array();              
    #TODO - check if "to" is < "from" = means that "to" is +1 day.
    $st = date("Y-m-d H:i", strtotime($date." +".$tt[2]." minutes"));
    $et = date("Y-m-d H:i", strtotime($date." +".$tt[3]." minutes"));
    $a = $st;
    $n = 0; //layout counter
    $b = date("Y-m-d H:i", strtotime($a." +".$int." minutes")); //default value for B is start time.
    for( $a = $st ; $b <= $et ; $b = 
                       date("Y-m-d H:i", strtotime($a." +".$int." minutes")))
    {
        $availabilityArr[date("Y-m-d", strtotime($a))][] = date("H:i", strtotime($a));
        $a = $b;
        $n++;
    }

Upvotes: 2

Views: 26625

Answers (5)

Clement Herreman
Clement Herreman

Reputation: 10536

Basically, it means that PHP doesn't have any allowed memory left. This can be tweaked, using memory_limit clause, in your php.ini.

If you are on a shared hosting, you might not be able to edit the php.ini. You still can try to use a .htaccess file :

  1. Create an file named .htaccess on the root of you web dir (usually /www or /web)
  2. Use the php_value clause :

    php_value memory_limit 128M #for example
    

This is caused by some of your code, that try to use too many, or too big variables. Usually it's an infinite loop, or fetching a lot of data from a DB into one array,

Upvotes: 3

Mat
Mat

Reputation: 6725

Your PHP environment currently has a memory limit of 32MB and the error message is telling you that it needs more memory than that in order to continue.

The memory limit is set by the memory_limit configuration option (See: https://www.php.net/manual/en/ini.core.php#ini.memory-limit). Either you need to refactor your code to use less memory or, if you really need that much memory, alter the memory_limit option.

To do this globally for all php scripts on the server you can edit php.ini (where this is depends on your OS and where you installed PHP).

To set a temporary higher memory limit just for this script, you can do the following:

$old_limit = ini_set( "memory_limit", "128M" );

(... the code that needs the extra memory ...)

ini_set( "memory_limit", $old_limit );

To reduce memory usage, try using unset() on any variables you don't need any more as a start.

Upvotes: 0

RRStoyanov
RRStoyanov

Reputation: 1172

It's PHP error.

in .htaccess you can set that

php_value memory_limit 90M

On top of your php files you can set

ini_set("memory_limit", "90M");

Upvotes: 4

jim
jim

Reputation: 9138

Sounds like a PHP error to be honest.

See this: http://www.bluehostforum.com/showthread.php?14500-Allowed-memory-size-of-33554432-bytes-exhausted

You need to edit the memory_limit setting in PHP.

Upvotes: 0

AJ.
AJ.

Reputation: 28174

Check your memory_limit setting in php.ini.

Upvotes: 0

Related Questions