使用 Symfony 开发模式执行并发请求时 Apache 崩溃
Apache crashing when doing concurrent requests with Symfony dev mode
我正在制作一个 symfony 3.4 应用程序作为 REST 服务(所以我安装了常用的 JMS 序列化程序、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),也不会发生同样的事情。
有什么办法可以彻底解决这个问题吗?
编辑:
根据要求
Can you add the apache error logs and php error logs?
每次重启就这样重复。我注意到这一行: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.
When you say apache crash means that you have to start apache again,
or you just get an error? Which error do you get?
我只是让通常的应用程序崩溃 window 说 "Apache has stopped working",如果我单击 "Close the application" 它会自行重新启动,导致崩溃的请求只是失败,没有状态代码或错误消息(这是预期的,因为与服务器的连接已停止)。如您所见,除了状态代码
之外,日志中没有特定错误
How you have setup apache and php mod_apache, php-fpm? Which apache
server limits do you have, how many php workers?
我不确定如何回答这个问题,我使用的是 XAMPP 包中的普通 Apache 和 php,没有对配置进行编辑。我可以告诉你 php 被加载为 apache 处理程序,所以没有 CGI 或 FastCGI。无论如何在简单的页面上或在 Symfony 中使用生产模式它都可以正常工作
新闻:
我发现,由于我正在执行 CORS 请求,它会为每个请求创建一个会话文件,我修复了它,它略微改善了我的问题,但它仍然存在
我曾尝试使用 Redis 作为 PHP 的会话处理程序,但它实际上让事情变得更糟
我做了一个简单的测试,我调用同一个页面(使用会话)1000 次,只要我把 session_write_close();
放在最后它就可以正常工作,否则它会崩溃
如我上一条评论所述,我尝试使用 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。
这些说明比上面 link 中发布的说明更具体 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>
我正在制作一个 symfony 3.4 应用程序作为 REST 服务(所以我安装了常用的 JMS 序列化程序、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),也不会发生同样的事情。
有什么办法可以彻底解决这个问题吗?
编辑: 根据要求
Can you add the apache error logs and php error logs?
每次重启就这样重复。我注意到这一行: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.
When you say apache crash means that you have to start apache again, or you just get an error? Which error do you get?
我只是让通常的应用程序崩溃 window 说 "Apache has stopped working",如果我单击 "Close the application" 它会自行重新启动,导致崩溃的请求只是失败,没有状态代码或错误消息(这是预期的,因为与服务器的连接已停止)。如您所见,除了状态代码
之外,日志中没有特定错误How you have setup apache and php mod_apache, php-fpm? Which apache server limits do you have, how many php workers?
我不确定如何回答这个问题,我使用的是 XAMPP 包中的普通 Apache 和 php,没有对配置进行编辑。我可以告诉你 php 被加载为 apache 处理程序,所以没有 CGI 或 FastCGI。无论如何在简单的页面上或在 Symfony 中使用生产模式它都可以正常工作
新闻:
我发现,由于我正在执行 CORS 请求,它会为每个请求创建一个会话文件,我修复了它,它略微改善了我的问题,但它仍然存在
我曾尝试使用 Redis 作为 PHP 的会话处理程序,但它实际上让事情变得更糟
我做了一个简单的测试,我调用同一个页面(使用会话)1000 次,只要我把
session_write_close();
放在最后它就可以正常工作,否则它会崩溃
如我上一条评论所述,我尝试使用 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。
这些说明比上面 link 中发布的说明更具体 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>