【问题标题】:Apache crashing when doing concurrent requests with Symfony dev mode使用 Symfony 开发模式执行并发请求时 Apache 崩溃
【发布时间】:2017-12-18 19:37:51
【问题描述】:

我正在制作一个 symfony 3.4 应用程序作为 REST 服务(所以我安装了常用的 JMS Serializer、FoSRest 和 lexik/jwt-authentication-bundle)并在 XAMPP(Windows 10)上对其进行测试。
当我使用 app_dev.php 作为端点通过我的前端应用程序发出 XHR 请求时,它(非常)经常发生 Apache 在同时发出 2 个以上请求时崩溃。
在这里和那里阅读,看起来这个问题通常是由尝试写入会话文件引起的,因为 symfony 默认会话处理程序是 session.handler.native_file。
所以我首先尝试输入null(根据文档,它使用原生 PHP 会话处理程序),这减少了崩溃发生的频率,但并没有完全解决问题
然后我尝试使用Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler,这使得崩溃发生的次数比以前更少,但仍然偶尔会发生崩溃

现在我正在使用数据库作为会话处理程序,尽管我注意到当我发出 XHR 请求时没有在数据库上写入会话(但如果我打开应用程序提供的普通网页,它会这样做),这不应该让我感到惊讶,因为我设置了我的 security.yml 使得 REST 路由必须是无状态的,但是玩弄 handler_id 配置会影响我的 apache 崩溃的频率

如果我打开由同一个应用程序提供的多个网页,则不会发生同样的事情,如果我使用生产端点 (app.php) 也不会发生同样的事情。

有没有办法彻底解决这个问题?

编辑: 根据要求

可以添加apache错误日志和php错误日志吗?

每次重新启动时都会如此重复。我注意到这条线:AH00428: Parent: child process 29076 exited with status 3221226356 -- Restarting. 这可能会很有趣

[Sun Dec 17 00:39:58.548676 2017] [mpm_winnt:notice] [pid 17564:tid 532] AH00428: Parent: child process 22856 exited with status 3221226356 -- Restarting.
[Sun Dec 17 00:39:59.544151 2017] [ssl:warn] [pid 17564:tid 532] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sun Dec 17 00:39:59.740710 2017] [mpm_winnt:notice] [pid 17564:tid 532] AH00455: Apache/2.4.26 (Win32) OpenSSL/1.0.2l PHP/7.1.7 configured -- resuming normal operations
[Sun Dec 17 00:39:59.740710 2017] [mpm_winnt:notice] [pid 17564:tid 532] AH00456: Apache Lounge VC14 Server built: Jun 15 2017 12:39:41
[Sun Dec 17 00:39:59.740710 2017] [core:notice] [pid 17564:tid 532] AH00094: Command line: 'c:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
[Sun Dec 17 00:39:59.746705 2017] [mpm_winnt:notice] [pid 17564:tid 532] AH00418: Parent: Created child process 29076
[Sun Dec 17 00:40:01.201423 2017] [ssl:warn] [pid 29076:tid 592] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sun Dec 17 00:40:01.414295 2017] [ssl:warn] [pid 29076:tid 592] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sun Dec 17 00:40:01.455312 2017] [mpm_winnt:notice] [pid 29076:tid 592] AH00354: Child: Starting 150 worker threads.
[Sun Dec 17 00:40:17.006680 2017] [mpm_winnt:notice] [pid 17564:tid 532] AH00428: Parent: child process 29076 exited with status 3221226356 -- Restarting.
[Sun Dec 17 00:40:17.371667 2017] [ssl:warn] [pid 17564:tid 532] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sun Dec 17 00:40:17.403690 2017] [mpm_winnt:notice] [pid 17564:tid 532] AH00455: Apache/2.4.26 (Win32) OpenSSL/1.0.2l PHP/7.1.7 configured -- resuming normal operations
[Sun Dec 17 00:40:17.403690 2017] [mpm_winnt:notice] [pid 17564:tid 532] AH00456: Apache Lounge VC14 Server built: Jun 15 2017 12:39:41
[Sun Dec 17 00:40:17.403690 2017] [core:notice] [pid 17564:tid 532] AH00094: Command line: 'c:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
[Sun Dec 17 00:40:17.409694 2017] [mpm_winnt:notice] [pid 17564:tid 532] AH00418: Parent: Created child process 24332
[Sun Dec 17 00:40:18.667139 2017] [ssl:warn] [pid 24332:tid 524] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sun Dec 17 00:40:18.858441 2017] [ssl:warn] [pid 24332:tid 524] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sun Dec 17 00:40:18.895469 2017] [mpm_winnt:notice] [pid 24332:tid 524] AH00354: Child: Starting 150 worker threads.
[Sun Dec 17 00:40:20.972550 2017] [mpm_winnt:notice] [pid 17564:tid 532] AH00428: Parent: child process 24332 exited with status 3221226356 -- Restarting.
[Sun Dec 17 00:40:21.481091 2017] [ssl:warn] [pid 17564:tid 532] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sun Dec 17 00:40:21.513627 2017] [mpm_winnt:notice] [pid 17564:tid 532] AH00455: Apache/2.4.26 (Win32) OpenSSL/1.0.2l PHP/7.1.7 configured -- resuming normal operations
[Sun Dec 17 00:40:21.513627 2017] [mpm_winnt:notice] [pid 17564:tid 532] AH00456: Apache Lounge VC14 Server built: Jun 15 2017 12:39:41
[Sun Dec 17 00:40:21.513627 2017] [core:notice] [pid 17564:tid 532] AH00094: Command line: 'c:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
[Sun Dec 17 00:40:21.519144 2017] [mpm_winnt:notice] [pid 17564:tid 532] AH00418: Parent: Created child process 27440
[Sun Dec 17 00:40:22.991094 2017] [ssl:warn] [pid 27440:tid 552] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sun Dec 17 00:40:23.266105 2017] [ssl:warn] [pid 27440:tid 552] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sun Dec 17 00:40:23.301132 2017] [mpm_winnt:notice] [pid 27440:tid 552] AH00354: Child: Starting 150 worker threads.

当你说 apache crash 意味着你必须重新启动 apache, 或者你只是得到一个错误?你得到哪个错误?

我只是看到通常的应用程序崩溃窗口说“Apache 已停止工作”,如果我单击“关闭应用程序”它会自行重新启动,导致崩溃的请求只是失败,没有状态代码或错误消息(即预期因为与服务器的连接停止)。如您所见,除了该状态代码外,日志中没有特定错误

你是如何设置 apache 和 php mod_apache, php-fpm 的?哪个阿帕奇 你有服务器限制,有多少 php worker?

我不确定如何回答这个问题,我使用的是 XAMPP 包中的股票 apache 和 php,没有对配置进行编辑。我可以告诉你 php 是作为 apache 处理程序加载的,所以没有 CGI 或 FastCGI。无论如何,在简单页面上或在 Symfony 中使用生产模式都可以正常工作

新闻:

  1. 我发现,由于我在执行 CORS 请求,它正在为每个请求创建一个会话文件,我修复了这个问题,它稍微改善了我的问题,但它仍然存在

  2. 我曾尝试使用 redis 作为 PHP 的会话处理程序,但它实际上让事情变得更糟

  3. 我做了一个简单的测试,我调用了同一个页面(使用会话)1000 次,只要我把session_write_close(); 放在最后,它就可以正常工作,否则它会崩溃

    李>

【问题讨论】:

标签: apache symfony session crash symfony3.x


【解决方案1】:

正如我在上一条评论中所述,我尝试使用 FastCGI 并解决了该问题。 https://blog.tiger-workshop.com/fix-various-apache-crashes-on-windows/

在此页面上,有 2 条针对我收到的错误的建议 AH00428: Parent: child process 29076 exited with status 3221226356 -- Restarting. 一种解决方法是将以下行添加到 httpd.conf

<IfModule mpm_winnt_module>
   ThreadStackSize 8388608
</IfModule>

但它没有用。第二个修复与使用 PHP 作为 Apache 处理程序 https://github.com/vlucas/phpdotenv/issues/76 时在 Windows 中发生的错误有关,因此我按照建议切换到 FastCGI。
这些说明比上面链接中发布的更具体到 XAMPP。您需要编辑文件xampp\apache\conf\extra\httpd-xampp.conf

评论以下几行

#
# PHP-Module setup
#
#LoadFile "C:/xampp/php/php7ts.dll"
#LoadFile "C:/xampp/php/libpq.dll"
#LoadModule php7_module "C:/xampp/php/php7apache2_4.dll"
#
#<FilesMatch "\.php$">
#    SetHandler application/x-httpd-php
#</FilesMatch>
#<FilesMatch "\.phps$">
#    SetHandler application/x-httpd-php-source
#</FilesMatch>
[...] (This one is further down in the file)
# 
#<IfModule php7_module>
#    PHPINIDir "C:/xampp/php"
#</IfModule>

并添加这些行

LoadModule fcgid_module modules/mod_fcgid.so

<IfModule fcgid_module>
   FcgidMaxProcesses 300
   FcgidMaxProcessesPerClass 300

   FcgidOutputBufferSize 65536
   FcgidConnectTimeout 10
   FcgidProcessLifeTime 0
   FcgidMaxRequestsPerProcess 0
   FcgidMinProcessesPerClass 0
   FcgidFixPathinfo 0
   FcgidProcessLifeTime 0
   FcgidZombieScanInterval 20
   FcgidMaxRequestLen 536870912
   FcgidIOTimeout 120
   FcgidTimeScore 3

   FcgidPassHeader Authorization

   FcgidInitialEnv PHPRC "C:\\xampp\\php"
   FcgidInitialEnv PATH "C:\\xampp\\php;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;"
   FcgidInitialEnv SystemRoot "C:\\Windows"
   FcgidInitialEnv SystemDrive "C:"
   FcgidInitialEnv TEMP "C:\\xampp\\tmp"
   FcgidInitialEnv TMP "C:\\xampp\\tmp"
   FcgidInitialEnv windir "C:\\Windows"

   DirectoryIndex index.html index.htm index.php

   <Files ~ "\.php$">
      Options Indexes FollowSymLinks ExecCGI
      AddHandler fcgid-script .php
      FcgidWrapper "C:/xampp/php/php-cgi.exe" .php
   </Files>
</IfModule>

【讨论】:

    猜你喜欢
    • 2022-07-06
    • 1970-01-01
    • 2019-02-25
    • 2015-01-22
    • 1970-01-01
    • 1970-01-01
    • 2013-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多