Symfony不服务并发请求 [英] Symfony not serving concurrent requests

查看:40
本文介绍了Symfony不服务并发请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是我的Symfony应用程序在具有 Apache/2.4.6(CentOS)PHP/5.6.31 MySQL 5.7.19 的远程计算机上运行并发请求.意思是当同时要求两个不同的页面时.第一个必须完成才能渲染第二个.

My problem is that my Symfony application running on a remote machine with Apache/2.4.6 (CentOS) PHP/5.6.31 MySQL 5.7.19 does not handle concurrent requests. Meaning that when asking for two different pages at the same time. First one has to finish before second one can be rendered.

我在同一台服务器上的另一个站点 用纯PHP编写,在同一时间呈现尽可能多的页面没有问题,(它使用了弃用的mysql连接,而不是像Doctrine那样的pdo).

I have a another site on the same server written in plain Php which has no problem rendering as many pages as possible at the same time (it uses deprecated mysql connection not pdo like Doctrine).

那表示我已经进行了以下测试:我插入了一个sleep(3);在我的DefaultController上.我请求了该页面,并同时请求了另一个页面.请参阅下面的两个探查器:

That said I have done the following test: I have inserted a sleep(3); at my DefaultController. I requested that page and simultaneously requested a different one. See the two profilers below:

带有睡眠的页面(称为第一页):页面没有睡眠(称为第二页).

Page with sleep (called 1st): Page without sleep (called 2nd).

  • 第1页的正常加载时间为 782ms
  • 第2页的正常加载时间为 108ms

如您所见,Symfony的Http防火墙将占用第二页的所有时间.我的猜测(可能是愚蠢的)是第一个操作将保持数据库连接,并且只有在完成该操作之前,它才允许其他请求使用它.特别是与Doctrine对PDO连接的使用有关.

As you can see Symfony's Http Firewall is taking all of the time of the second page to load. My guess (might be stupid) is that 1st action holds the database connection and only until it has finished with it does it let it go for other requests to use it. And especially something having to do with Doctrine's use of PDO connection.

通过这种方式,我已经阅读了帮助和类似文章的文章:-做什么的Symfony防火墙需要这么长时间?-为什么构建PDO连接缓慢?- https://www.drupal.org/node/1064342

By the way I have already read help and articles like: - What is the Symfony firewall doing that takes so long? - Why is constructing PDO connection slow? - https://www.drupal.org/node/1064342

P.S. .我尝试在apache配置中同时使用app.php和app_dev.php.坚持app_dev.php,所以我可以有探查器.使用Symfony的内置服务器进行本地开发具有相同的结果

推荐答案

在PHP中打开同一会话的并发请求数不能为2,因此当您使用防火墙时,Symfony会锁定用户会话,直到您释放它,不允许其他页面呈现.

You can't not have 2 concurrent request for the same sessions open in PHP so when you use a firewall Symfony locks the user session and until you release it, does not allow other pages to render.

关闭会话后,您将释放锁:

You will release the lock once you close the session:

$session->save();

这有一些含义,在那之后您将无法更新会话属性.

This has some implications, after that you can't update your session attributes.

会话管理: https://symfony.com/doc/current/components/http_foundation/sessions.html

会话界面: http://api.symfony.com/4.0/Symfony/Component/HttpFoundation/Session/SessionInterface.html#method_save

如果您有多个具有不同会话的并发用户,则PHP将同时处理该请求.

If you have multiple concurrent users with different sessions PHP will serve concurrently that requests.

这篇关于Symfony不服务并发请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆