duanbei1903 2013-09-05 07:35
浏览 39
已采纳

Symfony1提高了AJAX的动作速度

I have a speed issue with Symfony 1.4 and AJAX.

My routing:

ajax_search:
      url:   /search.:sf_format
      param: { module: article, action: articlesAjaxSearch, sf_format: html }
      requirements:
        sf_format: (?:html|js)

My js:

jQuery.ajax({
    type: 'GET',
    url:  jQuery('#searchform').attr('action'),
    data:  form_data,
    success: function(result)
    {
       jQuery("#searchform #searchresult").html(result).slideDown('fast');
    }
});

My action:

public function executeArticlesAjaxSearch(sfWebRequest $request) { 
          $this->getResponse()->setContent("<html><body>Hello, World!</body></html>");

            return sfView::NONE;

    }

This is a shorter version, but I need to improve speed. The AJAX call need around 200 ms to fetch this HTML content back.

Here's my log:

Sep 05 09:25:58 symfony [info] {articleActions} Call "articleActions->executeArticlesAjaxSearch()"
Sep 05 09:25:58 symfony [info] {sfWebResponse} Send status "HTTP/1.1 200 OK"
Sep 05 09:25:58 symfony [info] {sfWebResponse} Send header "Content-Type: text/html; charset=utf-8"
Sep 05 09:25:58 symfony [info] {sfWebDebugLogger} Configuration 0.88 ms (8)
Sep 05 09:25:58 symfony [info] {sfWebDebugLogger} Factories 53.19 ms (1)
Sep 05 09:25:58 symfony [info] {sfWebDebugLogger} Action "article/articlesAjaxSearch" 115.39 ms (1)
Sep 05 09:25:58 symfony [info] {sfWebDebugLogger} Database (Doctrine) 0.01 ms (3)
Sep 05 09:25:58 symfony [info] {sfWebDebugLogger} View "None" for "article/articlesAjaxSearch" 0.00 ms (1)
Sep 05 09:25:58 symfony [info] {sfWebResponse} Send content (39 o)

I need a solution to improve my ajax request speed for symfony 1

Sep 05 09:25:58 symfony [info] {sfWebDebugLogger} Action "article/articlesAjaxSearch" 115.39 ms (1)

I don’t understand why this take so long. Hope anyone can help me out I searching for more then one day for a solution.

The whole time of the ajax request take ~200ms without implement logic.

  • 写回答

1条回答 默认 最新

  • dongya9904 2013-09-05 07:50
    关注

    I would suggest just:

    public function executeArticlesAjaxSearch(sfWebRequest $request) {
      // ...
      echo json_encode($answer);
      exit;
    }
    

    You can put the module into separate application and disable unneeded filters. You can also use separate enviroment and disable, or use faster implementation for factories.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向