使用Symfony开发模式执行并发请求时Apache崩溃

问题描述 投票:1回答:1

我正在将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崩溃意味着你必须再次启动apache,或者你只是得到一个错误?你得到哪个错误?

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

你如何设置apache和php mod_apache,php-fpm?你有哪些apache服务器限制,有多少php工作者?

我不知道如何回答这个问题,我正在使用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个回答
0
投票

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

在这个页面上有两个错误的建议我收到AH00428: Parent: child process 29076 exited with status 3221226356 -- Restarting.一个修复是添加以下行到httpd.conf

<IfModule mpm_winnt_module>
   ThreadStackSize 8388608
</IfModule>

但它没有用。第二个修复与使用PHP作为Apache Handler 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>
© www.soinside.com 2019 - 2024. All rights reserved.