Doctrine appears to be taking well over 4MB of RAM to execute a single, simple query:

print memory_get_peak_usage()." <br>\n";
$q = Doctrine_Query::create()
    ->from('Directories d')
    ->where('d.DIRECTORY_ID = ?', 5);

$dir = $q->fetchOne();
print $dir['name']." ".$dir['description']."<br>\n";

print memory_get_peak_usage()." <br>\n";

/***************  OUTPUT:  **************************

testname testdescription


This is on a test database with very little data in it - the item that I am querying doesn't contain any data other than what is displayed here.

Is there potentially something wrong with the way I have the system set up, or is this standard memory usage for Doctrine?

Accepted Answer

From what I can see, you code doesn't seem to be wrong...

As a test, I've set up a quick example, with a very simple table (only four fields).

Here is the relevant code :


$test = Doctrine::getTable('Test')->find(1);


When doing that, I have this kind of output :

string '1,316,088' (length=9)
string '2,148,760' (length=9)

Considering the table is really simple and that I am only fetching one line, it seems "much" to me too -- but that's quite consistent with what you are getting, and with what I saw on other projects :-(

If you only need to display your data, and not work with it (ie update/delete/...), a solution might be to not fetch complex objects, but only a simple array :

$test = Doctrine::getTable('Test')->find(1, Doctrine::HYDRATE_ARRAY);

But, in this case, it doesn't make much of a difference, actually :-( :

string '1,316,424' (length=9)
string '2,107,128' (length=9)

Only 40 KB of difference -- well, with bigger objects / more lines, it might still be a good idea...

In the Doctrine manual, there is a page called Improving Performance ; maybe it could help you, especially for these sections :

Oh, btw : I did this test on PHP 5.3.0 ; maybe this can have an impact on the amount of memory used...

Written by Pascal MARTIN
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the community.
It is licensed under cc-wiki