du8828 2014-05-20 13:36
浏览 27
已采纳

Front Controller(app.php)多次调用1次请求

Here is my issue.

Situation

I am debugging symfony2 application (having some issues with posted data). On this occasion, i checked how many times app.php vs app_dev.php are called when handling a request.

example: request (from browser) : /demo/display/foos

logger in app.php (resp. app_dev.php):

//logger function 
function logtxt($logtxt, $name='myLog'){
  $fp = fopen($name.'.txt','a+');
  fseek($fp,SEEK_END);
  $newLog=date('H:i:s', time()).' - '.':'."
".$logtxt."
".'--------------------------------------------';
  fputs($fp,$newLog);
  fclose($fp); //basta
}

//logger call
logtxt('in app_dev.php ('.$_SERVER['SCRIPT_FILENAME'].')');

it basically adds a line in a logfile each time logtxt is called.

Issue

It appears that, in my applications, app_dev.php is called multiple times for a single request (mostly 2 times or 3 times). I tried with an empty project: app.php or app_dev.php are called only on time at each request.

I was thinking of redirections I would be doing, but this is not always the case. More amazing, there is sometimes a difference between app.php log count and app_dev.php log count for a same request!

I do not understand why the front-controller should be called more than once in a request. Also, it seems that it has some impact in production. For instance, in an old project, $_POST gets reset between these calls and its data seem to get lost (!).

for instance, for 1 same request, I will have in dev and prod envs:

15:45:51 - in app_dev.php:
in app_dev.php ($post: {"sort":"sort","property":"barcode"})

15:45:51 - in foo Controller:
fooControllerAction called ($post: {"sort":"sort","property":"barcode"})
--------------------------------------------
15:45:52 - in app_dev.php:
in app_dev.php ($post: [])
--------------------------------------------

whereas with app.php log:

15:44:07 - in app.php:
in app.php ($post: {"sort":"sort","property":"barcode"})

--------------------------------------------
15:44:07 - in app.php:
in app.php ($post: [])
--------------------------------------------
15:44:07 - in fooController:
fooControllerAction called ($post: [])
--------------------------------------------

Consequence: posted variable are usable by controller in dev environment, but not in prod environment, for the same request:

Solution

Is this behaviour known to someone ? I am eager to understand background justifying this, and check that it doesn't lead to errors. Also, if this is due to bad dev practice, I would change mine.

Thanks a lot in advance for sharing your wisdom!

Cheers,

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答