Drupal, the PHP Memory Limit, and PHP Data Objects (PDO)

While uploading some pictures of my new laptop I ran into a problem with the Drupal Image module running out of memory when it tried to create the different image styles of my uploaded photos.

The message I was getting was similar to the following although at the time I neglected to record the whole thing.

PHP Fatal error: Out of memory (allocated 34078720) (tried to allocate some amount of bytes) in some file on line some number

This is a pretty standard out of memory error so I contacted my web host, Canadian Web Hosting, and asked them if they could increase the memory limit. They complied as it seems my account is actually allowed a memory limit of 64M and added a custom php.ini in my public_html directory with the following in it:

memory_limit = 64M

This should have done the trick but for some reason it led to another fatal error message:

Fatal error: Class 'PDO' not found in /some directory/public_html/includes/database/database.inc on line 184

It seems the custom php.ini file was overriding whatever existing file had been loading the PDO class. After consulting Google I found the following information at php.net.

The PHP Data Objects (PDO) extension defines a lightweight, consistent interface for accessing databases in PHP. Each database driver that implements the PDO interface can expose database-specific features as regular extension functions. Note that you cannot perform any database functions using the PDO extension by itself; you must use a database-specific PDO driver to access a database server.

PDO provides a data-access abstraction layer, which means that, regardless of which database you're using, you use the same functions to issue queries and fetch data. PDO does not provide a database abstraction; it doesn't rewrite SQL or emulate missing features. You should use a full-blown abstraction layer if you need that facility.

PDO ships with PHP 5.1, and is available as a PECL extension for PHP 5.0; PDO requires the new OO features in the core of PHP 5, and so will not run with earlier versions of PHP.

Basically PDO is an extension that allows PHP to talk to the MySQL database which stores the data of my Drupal site. The following additional lines to the custom php.ini fixed the problem by initializing the extension and the MySQL specific PDO driver.

extension = pdo.so
extension = pdo_mysql.so

This did the trick and as you can see the site is up and running again. Hopefully this will save someone else the time spent diagnosing this problem.


You are my hero of the day! I had the same problem and your post sorted it out quickly.

Thanks a lot for taking the time to post this article.

Thank you very much. I have tried many things to resolver the issue but your article help me to understand the problem and resolve it. Thanks a lot again.

You are both very welcome. I'm glad the article helped at least a few people out.

Great Help!!!

This was the ticket! As a Drupal nube, working on configuring my son's developer instance site, I probably overdid it with installing various modules and ran up against the exact problems and solutions which you described clearly in your post. I thought I was locked out of the site... But now I'm back in and working! Thanks a lot!

Amazing, thank you for posting this! Worked like a charm! :)

Let me add my thanks to the others. You just saved my life, or at least my site.

Thank you so much for posting this. It worked a charm.

That was really useful - thanks for that info - worked a dream

You are a Lifesaver !!!

I was looking for this solution like for ever and almost give up. Great tip.

In which directory need to add php.inc?

It needs to be in your web root directory. This is where the index.php file should be.

why it does not work for me!! :'(

The best thing what you must do is that before uploading any image or data into durpal. You better check your memory and then try to upload your stuff. Last time when I tried to upload my http://best-essay-writing-service.reviews/essayshark-com-review/ blog article into durpal I faced the same problem you have faced. I reduced the article size and uploaded.