[英]All requests requiring connection to mysql are very very slow (using Phalcon)
[英]Phalcon very slow using Phalcon\Http\Response();
我在使用Phalcon时遇到一个非常奇怪的问题。
每当我在控制器内使用Response
,框架就会变得非常慢。 这是我的简单控制器:
<?php
// file: app/controllers/TestController.php
use Phalcon\Mvc\View;
class TestController extends ControllerBase
{
private $response;
public function initialize()
{
$this->view->setRenderLevel(View::LEVEL_NO_RENDER);
$this->response = new Phalcon\Http\Response();
$this->response->setStatusCode(200, "OK");
}
public function indexAction()
{
$this->response->setContent("phalcon")->send(); // very slow
}
}
每当我使用new Phalcon\\Http\\Response();
Phalcon变得非常慢。 例如,使用以下命令进行测试:
ab -c 50 -n 100 ...
请求/秒: 10
如果我使用空白控制器,我会得到
请求/秒: 1000+
路线是:
<?php
//file: app/config/routes.php
$router = new \Phalcon\Mvc\Router();
$router->add("/:controller/:action", array("controller" => "test", "action" => "index"));
我在AWS上进行了测试:
c4.large
PHP 5.5.9-1ubuntu4.6 (cli) (built: Feb 13 2015 19:17:11)
2 cpu - 3.75gb ram
Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.6
我们在使用osx 10.10.1的Macbook pro上遇到了相同的行为
问题是当我在响应上调用send()
方法时:
$this->response->send(); // slows down everything
如@ Phate01所建议,我尝试return $response;
而不是$response->send();
而且还是很慢
我转到此页面: http : //docs.phalconphp.com/en/latest/reference/response.html ,他们说
如果使用完整的MVC堆栈,则无需手动创建响应。 但是,如果您需要直接从控制器的操作返回响应,请遵循以下示例:
<?php
class FeedController extends Phalcon\Mvc\Controller
{
public function getAction()
{
// Getting a response instance
$response = new \Phalcon\Http\Response();
$feed = //.. load here the feed
//Set the content of the response
$response->setContent($feed->asString());
//Return the response
return $response;
}
}
?>
如您所见,它直接返回Response
对象。
我猜您应该在控制器外部调用->send()
,并且添加一些标头也将有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.