【问题标题】:Symfony 3.2.4 wildcard routing causes 100% cpu utilizationSymfony 3.2.4 通配符路由导致 100% cpu 利用率
【发布时间】:2017-02-28 12:34:45
【问题描述】:

我有一个很奇怪的问题:

我有两条路线: 第一个带有通配符:

/**
 * @Route("/test/{test}", name="test")
 * @param type $route
 */
public function testAction(Request $request, $test) {

    return $this->render('resource/showResource.html.twig', [
                'test' => $test
    ]);
}

第二个是没有通配符的:

/**
 * @Route("/test", name="test")
 * @param type $route
 */
public function testAction(Request $request) {

    return $this->render('resource/showResource.html.twig', [
                'test' => 'something'
    ]);
}

问题是当我运行第一个 (http://localhost/app_dev.php/test/1) 时,我的 CPU 利用率几乎达到 100%(进程:httpd.exe => Apache HTTP Server。

第二个就没有这个问题了。

是什么原因造成的?

【问题讨论】:

  • 对{$test}有什么具体要求吗?意味着它应该只是整数或其他东西......?
  • 最终它必须是整数,但现在没有必要。

标签: php apache symfony cpu-usage


【解决方案1】:

问题已解决: 在文件 base.html.twig 我没有这样的工作行:

    <script src="../vendors/jquery/dist/jquery.min.js"></script>

现在我正在为他们使用资产,一切都像魅力一样。

感谢大家的努力! :)

【讨论】:

    【解决方案2】:
    /**
     * @Route("/test/{test}", name="test")
     */
    public function testAction($test) {
    
        return $this->render('resource/showResource.html.twig', [
           'test' => $test
        ]);
    }
    

    【讨论】:

    • 删除请求 $request 没有帮助。
    • 我删除了 param 选项。那是不对的。这个函数现在看起来没问题,所以问题出在其他地方。看表格。
    • 无效。而且我暂时不使用表单,它只是一种测试方法。
    • Ou... 似乎是 showResource.html.twig 或 base.html.twig 导致了这个问题。当我从 showResource.html.twig 中删除这一行时: {% extends "base.html.twig" %} 然后一切都像魅力一样。但我需要这条线。
    【解决方案3】:

    试试下面的方法可能对你有帮助:

    /**
     * @Route("/test/{test}", name="test", requirements={"test": "\d+"})
     * @param type $route
     */
    public function testAction(Request $request, $test) {
    
        return $this->render('resource/showResource.html.twig', [
                'test' => $test
        ]);
    }
    

    查看http://symfony.com/doc/current/routing.html#adding-wildcard-requirements的更多详细信息

    【讨论】:

    • 不幸的是CPU使用率仍然相同,我试图使用需求,没有任何效果。在我之前的项目中,我没有遇到这样的问题,一切正常。
    猜你喜欢
    • 1970-01-01
    • 2019-01-14
    • 2017-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多