If you use mamp in cgi mode, to support opcache for instance if your page will take more than 30 seconds to load you get some error similar to
FastCGI: comm with server "/Applications/MAMP/fcgi-bin/php7.4.12.fcgi" aborted: idle timeout (30 sec)
How to increase that?
Enable xdebug, xdebug is for debugging purposes and you might be in the process of debugging a couple of breakpoints and moving around for a couple of minutes does it make sense that your debugger after 30 seconds stops and tells you OH, well I have to go we can't do this anymore!
So that's why turning the xdebug works, but should you do it?
If you get stuck once in the development and want a fast workaround use xdebug, otherwise don't! Xdebug makes your request a lot slower and gives you a development environment equal to hell, don't ever use xdebug constantly!!! only when you need to debug.
Add -idle-timeout
.
First let's talk about this little nifty menu.
This will let you modify a httpd.conf
file, but where is it? Is it the httpd.conf
file that will actually be used? NO.
This is just a file full of placeholders, mamp will replace the placeholders in this file and generate a new file and that file will be used at last.
Knowing that was very important since we are going to see the actual output and see how we can edit that to add idle-timeout
support.
The generated httpd.conf
file is somewhere in your computer, you have to find it first if you are on Linux or MacOS you can use
locate httpd.conf
I have a MacOS and I found that it was at
/Library/Application Support/appsolute/MAMP PRO/conf/httpd.conf
At the top of this file you will read that it is auto-generated by Mamp Pro.
# !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
# It is machine-generated by MAMP PRO, any changes made here will be lost!
Now in this file look for mod_fastcgi.c
you will find something like:
<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>
That is great now all we need to do is to add the -idle-timeout number
eg: -idle-timeout 3600
at the end of lines that start with FastCgiServer, so in this example we need to change it to the following (But DON'T! because this is the generated file just keep reading)
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
Remember that this is the generated file! in order to achieve this, we must modify the source file not this one, so let's just write it down somewhere so we can add it to the source file in the next step.
Using the Mamp Pro menu we open the source httpd.conf
file, again we search for mod_fastcgi.c
this time we'll find
<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>
Matching this to the output, you'll see that MAMP_FastCgiServer_MAMP
is the placeholder that gets replaced by FastCgiServer lines! So let's get rid of this placeholder and we'll add those lines ourselves here, in order to do this change the placeholder name slightly eg to: # M#A#M#P_FastCgiServer_MAMP
and add the FastCgiServer lines with idle-timeout
under or above it eg:
# 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
So the full section became
<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>
Save that restart the servers and look at the generated file
<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>
The operation was successful, if you changed your php versions just put the placeholder back-on, and repeat these steps.