【问题标题】:Symfony2 routing not working in production environmentSymfony2 路由在生产环境中不起作用
【发布时间】:2015-12-06 15:34:00
【问题描述】:

我正在尝试访问当前在本地工作但一旦部署到生产服务器就无法工作的 POST 路由。我已经删除了应用程序的名称,并在下面替换为 XXX。我的想法已经用完了,我想我已经尝试了这里发布的所有内容。

我们有一个非常相似的仅 POST 路由,它运行良好,但来自之前的部署。

我正在尝试访问路线 www.XXX.com/api/convert_mov

我的routing.yml

XXX_api_convert:
    path:     /api/convert_mov
    defaults: { _controller: XXXPartnerBundle:API:convert }
    methods:  [POST]

php app/console router:debug | grep api 返回

XXX_api_convert POST     ANY    ANY  /api/convert_mov

我跑了

php app/console cache:clear --env=prod

app/logs/prod.log 显示

request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "POST /api/convert_mov"" at /var/www/XXX/ppp/releases/20150903102317/vendor/symfony /symfony/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php 第 144 行 {"exception":"[object] (Symfony\Component\HttpKernel\Exception\NotFoundHttpException(code: 0): No route found for \"POST /api/convert_mov\" 在 /var/www/XXX/ppp/releases/20150903102317/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php:144, Symfony\Component\Routing\Exception\ ResourceNotFoundException(code: 0): at /var/www/XXX/ppp/releases/20150903102317/app/cache/prod/appProdUrlMatcher.php:738)"} []

即使在预热缓存之后,我也可以在 appProdUrlMatcher.php 中看到这一点

// XXX_api_convert
                if ($pathinfo === '/api/convert_mov') {
                    if ($this->context->getMethod() != 'POST') {
                        $allow[] = 'POST';
                        goto not_XXX_api_convert;
                    }

                    return array (  '_controller' => 'XXX\\PartnerBundle\\Controller\\APIController::convertAction',  '_route' => 'XXX_api_convert',);
                }
                not_XXX_api_convert:

            }

【问题讨论】:

  • 你有并发路线吗?
  • 好建议。我已经仔细检查过,路线和名称是唯一的。
  • 也许该路线仅在开发中?运行php app/console router:debug --env=prod | grep api
  • 不幸的是,即使带有 env=prod 标志,它也能正确显示在那里。预热后,我什至可以在 prod 缓存中看到 appProdUrlMatcher.php 中的代码

标签: symfony routing


【解决方案1】:

我设法用不同的部署脚本解决了这个问题。新脚本在服务器上执行了一些额外的任务,包括重新启动 PHP,这可能是答案。

Clearing the cache for the prod environment with debug false
Stopping php-fpm-5.5:                                      [  OK  ]
Starting php-fpm-5.5:                                      [  OK  ]
Nothing to update - your database is already in sync with the current entity metadata.
Installing assets as hard copies.
Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework
Installing assets for XXX\PartnerBundle into web/bundles/XXXpartner
Installing assets for Sonata\CoreBundle into web/bundles/sonatacore
Installing assets for Sonata\AdminBundle into web/bundles/sonataadmin
Installing assets for FOS\JsRoutingBundle into web/bundles/fosjsrouting
Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution
Running XXX:migrate
XXX:migrate - done

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多