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.