Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I recently installed Ubuntu 12.10 server with the stock version of Apache2, PHP and MySQL. Something is wrong with PHP - first I thought it was an issue with PHP Markdown, as the script came to a screeching halt (after being locked for a few seconds) on line 1420 with the error

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 130968 bytes) in /.../vendor/Markdown.php on line 1420

After a while I gave up debugging PHP Markdown, decided to temporarily disable it and move on with my project. Then I got the error:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) in /mnt/hgfs/Dropbox/Projects/twork/lib/database.php on line 78

This is line 78 of database.php:

$results = $stm->fetchAll(PDO::FETCH_ASSOC);

And as my entire database only contains about 20 rows at the moment, I think you'll agree that this error is utter bullshit. I recently ran this project on PHP 5.3 on a different system without problems. Something about my current PHP setup is causing loops to continue for ever and running out of memory.

IMPORTANT NOTE: Both PHP Markdown and PDO (MySQL) works perfectly in the CLI version of PHP on this very same system - the problem is only with Apache2 + PHP.

Are there any settings, bugs or quirks you know about that can cause this behaviour in PHP?

Here is my phpinfo()

share|improve this question
add comment

1 Answer 1

I'm not sure why you're focussing on the database. The error is really very clear: PHP has run out of allotted RAM. We can create hypothesises as to why this has happened but digging through other people's code (especially when it's PHP) is a loveless task. Let's just get this up and running.

Allow PHP to use more memory

You never know - the script might just be really flabby. There may be a memory leak. It might be a burst issue. Who knows. You'll never find out until you turn things up to eleven.

1.Edit php.ini:

sudoedit /etc/php5/apache2/php.ini
  1. Change memory_limit = 128M to memory_limit = 256M
  2. Restart PHP, or Apache (again, unfamilar with how mod_php actually works)

If it still continues to use all the memory in the world, I'd consider that a serious bug. If it only hits you on this one install

share|improve this answer
I'm not sure if you're actually insinuating that PHP needs more than 128 MB of ram to fetch a couple of rows from MySQL, because that would be retarded. In any case, I increased the memory limit to 512 MB of ram, and now PHP just crashes with a segfault instead: [notice] child pid 2076 exit signal Segmentation fault (11) –  Hubro Apr 10 '13 at 12:46
Also, I'm not focusing on the database. I'm focusing on the fact that mod_php is causing loops to continue infinitely and eat up all the allotted RAM. –  Hubro Apr 10 '13 at 12:49
Can you try a more memory-efficient approach? Something like... while ($row = $stm->fetch(PDO::FETCH_ASSOC)) /* do stuff */ –  Oli Apr 10 '13 at 12:56
It's not just a flabby script. The same operations in the CLI, as well as on a different server with PHP 5.3, take only a fraction of a second. Currently on this server, the script runs for almost 4 seconds before running out of memory and crashing. –  Hubro Apr 10 '13 at 18:02
@Codemonkey Yeah I'll agree with you. There's something wrong with PHP but it's likely (now I think about it) that neither of these two code segments are the actual cause. They're only trying to allocate 128KB and 32B respectively. The memory leak is present well before either of these scripts get involved. I'd purge all of PHP's config and try again but past that, I wouldn't know where to look. –  Oli Apr 10 '13 at 18:34
show 2 more comments

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.