如何在CakePHP中获得当前响应长度

时间:2015-06-05 08:29:47

标签: cakephp response content-length cakephp-2.5

我正在使用:CakePHP 2.5.6
试着像这样读取响应的长度:

App::uses('Controller', 'Controller');

Class AppController extends Controller {

    public function afterFilter() {
        parent::afterFilter();
        pr($this->response->length());
    }

}

但无效,返回的值为空 我该怎么做?

1 个答案:

答案 0 :(得分:0)

您应该尝试$this->response->length();

编辑: 或者使用$this->response->header();

阅读设置标题

在这两种情况下,您获得的价值可能都不准确,因为网络服务器可以更改内容/标题并调整大小。