logo
Ask your Symfony questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$10
How do I turn off the profiler on a per-action basis?

Symfony 1.4.8

Using Doctrine.

When I run a query with large query results, I receive this error:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 16 bytes) in /home/dev/tastingnotes/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Table.php on line 573


I noticed that if I deactivate the profiler option into databases.yml, everything works. So the profiler is part of the reason for the Out Of Memory error.

In config/databases.yml, we could do this:

all:
doctrine:
class: sfDoctrineDatabase
param:
dsn: 'mysql:dbname=xxx;host=localhost'
username: xxx
password: xxx
encoding: UTF8
profiler: false

dev:
doctrine:
class: sfDoctrineDatabase
param:
dsn: 'mysql:dbname=xxx;host=localhost'
username: xxx
password: xxx
encoding: UTF8
profiler: true


That way the profiler would be off in production and the scripts would run. But we do not want to handle things this way.

We could turn off the profiler everywhere, even in dev. But we do not want to handle things this way.

We want the profiler on, most of the time. But we want it off for one particular action, where very large results are expected.

How can we turn it off for just one action?

This question has been answered.

Lawrence Krubner | 02/07/11 at 5:17pm Edit


(2) Responses

See a threaded view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    02/08/11
    12:59pm
    Loban Rahman says:

    Firstly, why do u want the profiler on in production? I only use it for debugging and optimization. Perhaps you want to monitor the usage of all your child sites. First consider whether you need this or not. :-)

    Secondly, on to answering your question. The following code is used to enable the profiler (snippet from http://www.doctrine-project.org/documentation/manual/1_0/hu/component-overview:profiler)

    $profiler = new Doctrine_Connection_Profiler();
    $conn = Doctrine_Manager::connection();
    $conn->setListener($profiler);

    So, I would assume that to disable it, just disconnect the profiler from the connection $conn by removing/disabling the listener. Then, after your large query, re-add/enable the listener again.

    Or, disable the $profiler in all parts of your database.yml, and then manually add your the profiler as a listener in your code (probably ProjectConfiguration), but include a condition that checks to see if the current action is the one that will do the large query.

  • avatar
    Last edited:
    02/08/11
    11:58am
    Lawrence Krubner says:

    Thanks, Loban, but what do you mean when you say "just disconnect the profiler from the connection". When I try to set it to null, I get this error:

    Feb 08 11:43:04 symfony [err] {Doctrine_EventListener_Exception} Couldn't set eventlistener. EventListeners should implement either Doctrine_EventListener_Interface or Doctrine_Overloadable

This question has expired.





Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.