应用引擎上的 Symfony3 会话失败

Posted

技术标签:

【中文标题】应用引擎上的 Symfony3 会话失败【英文标题】:Symfony3 Session Failed on appengine 【发布时间】:2018-11-17 03:42:38 【问题描述】:

我想在 DB 上存储 Session,我在 symfony 文档中关注了这个 link

在本地环境中我没有任何问题,但是当我在 appengine 上进行部署时,我可以在日志中看到这个问题

2018-06-07 09:15:24 default[20180607t110053]  [07-Jun-2018 09:15:24] WARNING: [pool app] child 11 said into stderr: "NOTICE: php message: PHP Fatal error:  Uncaught PDOException: SQLSTATE[HY000] [2002] No such file or directory in /app/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php:403"
2018-06-07 09:15:24 default[20180607t110053]  [07-Jun-2018 09:15:24] WARNING: [pool app] child 11 said into stderr: "Stack trace:"
2018-06-07 09:15:24 default[20180607t110053]  [07-Jun-2018 09:15:24] WARNING: [pool app] child 11 said into stderr: "#0 /app/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php(403): PDO->__construct('mysql:host=;por...', 'root', 'MYPASS...', Array)"
2018-06-07 09:15:24 default[20180607t110053]  [07-Jun-2018 09:15:24] WARNING: [pool app] child 11 said into stderr: "#1 /app/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php(264): Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler->connect('mysql:host=;por...')"
2018-06-07 09:15:24 default[20180607t110053]  [07-Jun-2018 09:15:24] WARNING: [pool app] child 11 said into stderr: "#2 /app/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/SessionHandlerProxy.php(46): Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler->open('/tmp/sessions', 'PHPSESSID')"
2018-06-07 09:15:24 default[20180607t110053]  [07-Jun-2018 09:15:24] WARNING: [pool app] child 11 said into stderr: "#3 [internal function]: Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy->open('/tmp/sessions', 'PHP..."
2018-06-07 09:15:24 default[20180607t110053]  2018/06/07 09:15:24 [error] 9#9: *1 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught PDOException: SQLSTATE[HY000] [2002] No such file or directory in /app/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php:403
2018-06-07 09:15:24 default[20180607t110053]  Stack trace:
2018-06-07 09:15:24 default[20180607t110053]  #0 /app/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php(403): PDO->__construct('mysql:host=;por...', 'root', 'MYPASS...', Array)
2018-06-07 09:15:24 default[20180607t110053]  #1 /app/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php(264): Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler->connect('mysql:host=;por...')
2018-06-07 09:15:24 default[20180607t110053]  #2 /app/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/SessionHandlerProxy.php(46): Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler->open('/tmp/sessions', 'PHPSESSID')
2018-06-07 09:15:24 default[20180607t110053]  #3 [internal function]: Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy->open('/tmp/sessions', 'PHPSESSID')" while reading response header from upstream, client: 172.17.0.4, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "myproject.appspot.com"
2018-06-07 09:15:24 default[20180607t110053]  172.17.0.4 - - [07/Jun/2018:09:15:24 +0000] "GET / HTTP/1.1" 500 5 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/66.0.3359.181 Safari/537.36"

好像主机mysql是空的

mysql:host=;

【问题讨论】:

【参考方案1】:

我建议您检查一下yaml文件中是否配置了主机,如here所示。如果这不起作用,请查看此tutorial 以获取 Symphony 并在 App Engine 上运行。

还值得通过更改 database_host 值在此 thread 上测试此故障排除。 here 发布了类似的故障排除。

【讨论】:

以上是关于应用引擎上的 Symfony3 会话失败的主要内容,如果未能解决你的问题,请参考以下文章

无法访问应用引擎开发服务器上的 servlet 过滤器中的会话数据

弃用服务的公共使用

如何在 Symfony 中增加会话超时

会话 ID cookie 上的 Mcafee PCI 合规性失败?

Symfony3 不读取 Elastic Beanstalk 上的环境变量

如何为 Symfony3 上的 AJAX 调用添加 CSRF 保护?