dongquelu1239 2018-04-05 06:10
浏览 61

PHP Phalcon - 处理请求和打印站点内容使函数运行多次

I'm noticing that when navigating to any part of my Phalcon site, everything seems to be firing twice. As shown below, index.php and the subsequent controllers are visited twice. I write to a text file in each of these, and the content is duplicated.

index.php

...
fwrite(fopen("log.txt", "a+"),"index
");
...

BaseController::onConstruct()

...
fwrite(fopen("log.txt", "a+"), "base
");
...

Which on any request gives the result:

log.txt

index
base
index
base

I think this has something to do with the handling and output of the request, as

index.php

$app = new Application($di);
try{
    $response = $app->handle();
    $response->send();
    ...

gives the above result, while

index.php

$app = new Application($di);
try{
    $response = $app->handle();
    //$response->send();
    ...

Gives the following result (and a blank screen in the browser, so not really a solution):

log.txt

index
base

I've tried a few different ways of getting hold of the output and printing it, but everything gives the same, duplicated result:

index.php

$response = $app->handle();
$content = $response->getContent();
echo $content;

and the one-liner

index.php

$app->handle()->send();

This happens on both http and https requests, so I don't think it's an Nginx/redirect issue.

Doing everything twice must be more costly than just the one time, so what can I do to have stuff only run once?

Could it be a resource being loaded later and doing some magic? I've looked for <img> tags with empty sources and am aware of some issues regarding favicons, especially in Chrome (though I'm certain I fixed an issue like that earlier in development), but the result is the same in Chrome, Firefox and Opera.

A small update: going to View Source in the browser gives the unduplicated result. Is there something in printing the actual content that could cause this issue?

Thanks for any help.

  • 写回答

1条回答 默认 最新

  • duanla8800 2018-04-05 07:18
    关注

    The issue is no longer present after removing a call to $this->assets->addCss() on a non-existent CSS file. I had forgotten to remove the reference after removing the library from my project.

    Additional information: "every broken image or assets makes an additional request to the index file" which causes this issue

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度