gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 17:54:37 25 4
gpt4 key购买 nike

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

现在我正在使用数据库作为 session 处理程序,但我注意到当我发出 XHR 请求时数据库上没有写入任何 session (如果我打开应用程序提供的普通网页,则会出现这种情况),这应该不会让我感到惊讶,因为我设置了 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?

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

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 中使用生产模式,它都可以正常工作

新闻:

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

  2. 我尝试过使用 Redis 作为 PHP 的 session 处理程序,但实际上这让事情变得更糟

  3. 我做了一个简单的测试,我调用同一个页面(使用 session )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 处理程序时在 Windows 中发生的错误相关 https://github.com/vlucas/phpdotenv/issues/76所以我按照建议切换到 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>

关于使用 Symfony 开发模式执行并发请求时 Apache 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47845593/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com