views:

462

answers:

5

Hello, we are trying to build an application using the zend framework and have the following problem: "Some controller actions are called twice. This means that the actions gets called, finishes its execution and then gets called again".

We tracked this down by checking entries in a log file. For one request there where 2 entries in the log file.

Do you know anything that might be causing this problem? Is this related with the dispatch process of the Front Controller?

Regards,

+1  A: 

It might be a bug. Difficult to tell without more information.

Try logging a backtrace each time the action method is called.

<?php
trigger_error(var_export(debug_backtrace(), true));
trigger_error(var_export($_SERVER, true));
?>

This will give you tons of info in the error-log, so you'll want to export the result to a text-editor and munch through it there. And/or possibly modify the code to print less info.

A couple of things to look for:

  • Is the action-method called from different places?
  • Is the $_SERVER['UNIQUE_ID'] (or REQUEST_TIME) different?

If the unique-id is different then you've done two requests to the server. If not, try to figure it out from the backtrace.

+1  A: 

forward or action stack may be to reason

+1  A: 

try and use a debugger ( XDebug for example ) to see how your code is runned. focus on the dispatcher, something must have happened and the request action is not set as dispatched so it gets runned again.

solomongaby
A: 

(comment) I have this problem as well, different UNIQUE_ID and REQUEST_TIME, however the action is so simple I cannot understand how it's happening. The actions it happens on DO use Zend_Controller_Router_Route. Does your action?

A: 

We were having a similar problem. Some actions were executed twice. After much debugging and googling, found out the problem was a bug in ZFdebug. Installed this patch and everything went back to normal. Hope this helps someone else.

Eric