14

Hot to solve this problem and why it happens?

Zend Server Log:

PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 538798977 bytes) in C:\Program Files (x86)\Zend\Apache2\htdocs\test\modules\main.php on line 3

The file main.php does not produce any error, if it's executed directly from browser. However, if I use its functions from another PHO file, then Zend Log prints the above-mentioned error.

You Kuper
  • 1,113
  • 7
  • 18
  • 38

4 Answers4

15

I have also encounted this problem.

Increase the following variables so that your page execution will not stop:

  • max_input_time
  • memory_limit
  • max_execution_time
LittleBobbyTables - Au Revoir
  • 32,008
  • 25
  • 109
  • 114
Shail
  • 1,565
  • 11
  • 24
  • 8
    ...not technically *wrong* so no -1 but probably a bad suggestion. The original error indicates that you're (probably) using *way* too much memory - there's something smelly in your code (infinite loop?). To put it differently, if your page consumes that much memory every time if runs, for your host's sake hopefully you don't have many users :) – Ben May 01 '13 at 00:29
10

Either increase the memory limit in php.ini, or try to optimise any large data structures (like arrays) out of your application.

In any case, if your PHP application is using 128MB of RAM, something is probably going wrong.

Also, as noted by Fluffeh in the comments, what on earth are you doing to utilise 500MB of RAM?

slugonamission
  • 9,562
  • 1
  • 34
  • 41
8

Try this:

ini_set('memory_limit', '-1');

php.net/memory_limit

It will take unlimited memory usage of server.

2

In addition to user1427811 you can monitor time_limit and memory_limit before and after downloading the file:

function custom_put_contents($source_url='',$local_path=''){

    $time_limit = ini_get('max_execution_time');
    $memory_limit = ini_get('memory_limit');

    set_time_limit(0);
    ini_set('memory_limit', '-1');      

    $remote_contents=file_get_contents($source_url);
    $response=file_put_contents($local_path, $remote_contents);

    set_time_limit($time_limit);
    ini_set('memory_limit', $memory_limit); 

    return $response;
}
RafaSashi
  • 16,483
  • 8
  • 84
  • 94