如果您在 cgi 模式下使用 mamp,例如为了支持 opcache,如果您的页面加载时间超过 30 秒,您会收到类似以下内容的错误:
FastCGI: comm with server "/Applications/MAMP/fcgi-bin/php7.4.12.fcgi" aborted: idle timeout (30 sec)
如何增加?
这就是为什么打开 xdebug 有效,但是你应该这样做吗?
如果您在开发过程中遇到困难并希望快速解决问题,请使用 xdebug,否则不要! Xdebug 会让你的请求变慢很多,并给你一个地狱般的开发环境,永远不要经常使用 xdebug!仅当您需要调试时。
解决方案2
-idle-timeout
。首先我们来谈谈这个漂亮的小菜单。
这将让你修改一个
httpd.conf
文件,但是它在哪里?是实际使用的
httpd.conf
文件吗?没有。这只是一个充满占位符的文件,mamp将替换该文件中的占位符并生成一个新文件,最后将使用该文件。
了解这一点非常重要,因为我们将看到实际的输出,并了解如何编辑它以添加
idle-timeout
支持。第1步.找到生成的文件
httpd.conf
文件位于您计算机中的某个位置,如果您在Linux或MacOS上可以使用,则必须先找到它
locate httpd.conf
我有一个 MacOS,我发现它位于
/Library/Application Support/appsolute/MAMP PRO/conf/httpd.conf
在此文件的顶部,您将看到它是由 Mamp Pro 自动生成的。
# !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
# It is machine-generated by MAMP PRO, any changes made here will be lost!
第2步.在生成的输出中找到有关fastcgi的部分mod_fastcgi.c
,您会发现类似以下内容:
<IfModule mod_fastcgi.c>
# URIs that begin with /fcgi-bin/, are found in /var/www/fcgi-bin/
Alias /fcgi-bin/ "/Applications/MAMP/fcgi-bin/"
# Anything in here is handled as a "dynamic" server if not defined as "static" or "external"
<Directory "/Applications/MAMP/fcgi-bin/">
SetHandler fastcgi-script
Options +ExecCGI
</Directory>
# Anything with one of these extensions is handled as a "dynamic" server if not defined as
# "static" or "external". Note: "dynamic" servers require ExecCGI to be on in their directory.
AddHandler fastcgi-script .fcgi .fpl
FastCgiIpcDir /Applications/MAMP/Library/logs/fastcgi
FastCgiServer /Applications/MAMP/fcgi-bin/php8.1.1.fcgi -socket fgci8.1.1.sock
FastCgiServer /Applications/MAMP/fcgi-bin/php7.4.21.fcgi -socket fgci7.4.21.sock
</IfModule>
步骤 3. 将空闲超时添加到生成文件中的 FastCgiServer 行-idle-timeout number
,例如:
-idle-timeout 3600
,因此在本例中我们需要将其更改为以下内容(但是不要!因为这是生成的文件,请继续阅读)
FastCgiServer /Applications/MAMP/fcgi-bin/php8.1.1.fcgi -socket fgci8.1.1.sock -idle-timeout 3600
FastCgiServer /Applications/MAMP/fcgi-bin/php7.4.21.fcgi -socket fgci7.4.21.sock -idle-timeout 3600
记住这是生成的文件!为了实现这一目标,我们必须修改源文件而不是这个文件,所以让我们将其写在某处,以便我们可以在下一步中将其添加到源文件中。第4步.将我们编写的行放入httpd.conf的源文件中
httpd.conf
文件,再次搜索
mod_fastcgi.c
这次我们会发现
<IfModule mod_fastcgi.c>
# URIs that begin with /fcgi-bin/, are found in /var/www/fcgi-bin/
Alias /fcgi-bin/ "/Applications/MAMP/fcgi-bin/"
# Anything in here is handled as a "dynamic" server if not defined as "static" or "external"
<Directory "/Applications/MAMP/fcgi-bin/">
SetHandler fastcgi-script
Options +ExecCGI
</Directory>
# Anything with one of these extensions is handled as a "dynamic" server if not defined as
# "static" or "external". Note: "dynamic" servers require ExecCGI to be on in their directory.
AddHandler fastcgi-script .fcgi .fpl
MAMP_ActionPhpCgi_MAMP
FastCgiIpcDir /Applications/MAMP/Library/logs/fastcgi
MAMP_FastCgiServer_MAMP
</IfModule>
将其与输出匹配,您将看到 MAMP_FastCgiServer_MAMP
是被 FastCgiServer 行替换的占位符!因此,让我们摆脱这个占位符,我们将自己在此处添加这些行,为此,请稍微更改占位符名称,例如:
# M#A#M#P_FastCgiServer_MAMP
,并在其下方或上方添加带有
idle-timeout
的 FastCgiServer 行,例如:
# M#A#M#P_FastCgiServer_MAMP
FastCgiServer /Applications/MAMP/fcgi-bin/php8.1.1.fcgi -socket fgci8.1.1.sock -idle-timeout 3600
FastCgiServer /Applications/MAMP/fcgi-bin/php7.4.21.fcgi -socket fgci7.4.21.sock -idle-timeout 3600
所以完整的部分变成了
<IfModule mod_fastcgi.c>
# URIs that begin with /fcgi-bin/, are found in /var/www/fcgi-bin/
Alias /fcgi-bin/ "/Applications/MAMP/fcgi-bin/"
# Anything in here is handled as a "dynamic" server if not defined as "static" or "external"
<Directory "/Applications/MAMP/fcgi-bin/">
SetHandler fastcgi-script
Options +ExecCGI
</Directory>
# Anything with one of these extensions is handled as a "dynamic" server if not defined as
# "static" or "external". Note: "dynamic" servers require ExecCGI to be on in their directory.
AddHandler fastcgi-script .fcgi .fpl
MAMP_ActionPhpCgi_MAMP
FastCgiIpcDir /Applications/MAMP/Library/logs/fastcgi
# M#A#M#P_FastCgiServer_MAMP
FastCgiServer /Applications/MAMP/fcgi-bin/php8.1.1.fcgi -socket fgci8.1.1.sock -idle-timeout 3600
FastCgiServer /Applications/MAMP/fcgi-bin/php7.4.21.fcgi -socket fgci7.4.21.sock -idle-timeout 3600
</IfModule>
第 5 步。通过检查新生成的文件来测试我们的更改
<IfModule mod_fastcgi.c>
# URIs that begin with /fcgi-bin/, are found in /var/www/fcgi-bin/
Alias /fcgi-bin/ "/Applications/MAMP/fcgi-bin/"
# Anything in here is handled as a "dynamic" server if not defined as "static" or "external"
<Directory "/Applications/MAMP/fcgi-bin/">
SetHandler fastcgi-script
Options +ExecCGI
</Directory>
# Anything with one of these extensions is handled as a "dynamic" server if not defined as
# "static" or "external". Note: "dynamic" servers require ExecCGI to be on in their directory.
AddHandler fastcgi-script .fcgi .fpl
FastCgiIpcDir /Applications/MAMP/Library/logs/fastcgi
# M#A#M#P_FastCgiServer_MAMP
FastCgiServer /Applications/MAMP/fcgi-bin/php8.1.1.fcgi -socket fgci8.1.1.sock -idle-timeout 3600
FastCgiServer /Applications/MAMP/fcgi-bin/php7.4.21.fcgi -socket fgci7.4.21.sock -idle-timeout 3600
</IfModule>
操作成功,如果您更改了 php 版本,只需重新打开占位符,然后重复这些步骤。