OpenCart类别页面加载时间

时间:2013-12-06 02:45:27

标签: php opencart

我对脚本进行了一些基准测试,该脚本加载了类别route=product/category中的所有产品。我在整个脚本中插入了一些microtime函数,得到了以下结果:

Array
(
    [0] => 1386295629.1175
    [1] => 1386295629.1556
    [2] => 1386295629.1562
    [3] => 1386295629.1562
    [4] => 1386295629.4826
    [5] => 1386295629.49
    [6] => 1386295629.4908
    [7] => 1386295629.491
)

从开始到结束,加载整个页面的数据需要0.3735秒。这包括所有SQL查询和图像大小调整(如果需要)。我在这个页面上运行了基准测试:

http://www.hollywoodcollectibles.com/baseball/autographed-baseball-balls

您会注意到加载该页面需要10秒以上,大部分时间用于请求而不是响应。所以瓶颈实际上根本不在SQL中。大多数其他类别,包含较少量的产品,根本不会遇到这个瓶颈。

我运行了另一个基准测试,这次测量渲染实际输出所需的时间,$this->response->setOutput($this->render());

Array
(
    [0] => 1386296946.8589
    [1] => 1386296964.206
)

现在,我们正在某个地方。 Opencart花了17.34秒来渲染输出。

在此之后,我迷路了。任何人都可以指出我在Opencart中$this->render()函数的位置,并可能给我任何其他建议,在哪里寻找瓶颈?

1 个答案:

答案 0 :(得分:1)

我不知道这对你有帮助,但该功能在system/engine/controller.php

protected function render() {
    foreach ($this->children as $child) {
        $this->data[basename($child)] = $this->getChild($child);
    }

    if (file_exists(DIR_TEMPLATE . $this->template)) {
        extract($this->data);

        ob_start();

        require(DIR_TEMPLATE . $this->template);

        $this->output = ob_get_contents();

        ob_end_clean();

        return $this->output;
    } else {
        trigger_error('Error: Could not load template ' . DIR_TEMPLATE . $this->template . '!');
        exit();             
    }
}

system/library/pagination.php中有另一个函数render(),但这只是我相信的分页。

相关问题