How to Configure FastCGI on WAMP and solve ERR_CONNECTION_RESET error

How to Configure FastCGI on WAMP and solve ERR_CONNECTION_RESET error
COMMENTS (0)
Tweet

What is FastCGI and how does it work?

FastCGI is a method for speeding up and improving the performance of web applications by compelling the server to execute time-consuming code through the Common Gateway Interface (CGI). According to FastCGI developers, requests that are being sent to a website by a specific application or a program can speed up by 3 to 30 times using FastCGI.

The CGI scripts execute time-consuming code (such as opening a database, searching for a specific item in the data base etc) only once instead of executing it every time the script is loaded.

FastCGI isn’t limited by server specific APIs. It is a scalable and language independent plugin/extension that needs minor changes to the servers apps (such as Perl or Tcl scripts and C and C++ programs ) to optimize the performance.

FCGI use a set if defined processes to handle multiple requests. Every FastCGI process individually handles multiple requests, thereby avoiding the overhead of per-request process creation and termination.

Many ecommerce developers use this technique to improve their web performance and decrease load times.

What’s ERR_CONNECTION_RESET error and why does it occur?

When working with Magento2 or Laravel on a Windows Platform with Apache/2.4.x (Win64) PHP/7.x.x, you may encounter random errors and Apache continuously keeps on crashing with ERR_CONNECTION_RESET error in console.
err_connecton_reset
Looking deeply into this problem, an error in the apache error log file was found.

 status_3221226356
 number of events
Status 3221226356 indicates a heap correction (STATUS_HEAP_CORRUPTION). This issue is often faced by developers working on Windows environment because of smaller Apache’s default stack size. And it usually happens when working with PHP code that allocates a lot of stacks.

 

How to Solve ERR_CONNECTION_RESET error using FastCGI

 How to Configure FastCGI with WAMP

1. Download FastCGI (mod_fcgid) from http://www.apachelounge.com/download/ and extract the mod_fcgid.so file in <wamp_directory>\bin\apache\apache<version>\modules directory.

2. Create a file httpd-fcgid.conf in <wamp_directory>\bin\apache\apache<version>\conf\extra and add the following content in it.

LoadModule fcgid_module modules/mod_fcgid.so

<IfModule fcgid_module>
FcgidMaxProcesses 300
FcgidMaxProcessesPerClass 300

FcgidOutputBufferSize 65536
FcgidConnectTimeout 500
FcgidProcessLifeTime 0
FcgidMaxRequestsPerProcess 0
FcgidMinProcessesPerClass 0
FcgidFixPathinfo 0
FcgidProcessLifeTime 0
FcgidZombieScanInterval 20
FcgidMaxRequestLen 536870912
FcgidIOTimeout 500
FcgidTimeScore 3

FcgidPassHeader Authorization

FcgidInitialEnv PHPRC ${INSTALL_DIR}/bin/apache/apache${VERSION_APACHE}/bin"
FcgidInitialEnv SystemRoot "C:\\Windows"
FcgidInitialEnv SystemDrive "C:"
FcgidInitialEnv TEMP "C:\\WINDOWS\\TEMP"
FcgidInitialEnv TMP "C:\\WINDOWS\\TEMP"
FcgidInitialEnv windir "C:\\WINDOWS"

DirectoryIndex index.html index.htm index.php

<Files ~ "\.php$">
Options Indexes FollowSymLinks ExecCGI
AddHandler fcgid-script .php
FcgidWrapper "${INSTALL_DIR}/bin/php/php${VERSION_PHP}/php-cgi.exe" .php
</Files>
</IfModule>

Save and Close.

3. Edit apache configuration file by clicking on the WAMP icon in the taskbar and select httpd.conf in the Apache menu.

4. In the httpd.conf file, find the line similar to LoadModule php7_module "${INSTALL_DIR}/bin/php/php7.1.16/php7apache2_4.dll" and add the following line above it. DEFINE VERSION_PHP 7.1.16
finally the configuration should look like
DEFINE VERSION_PHP 7.1.16
LoadModule php7_module “${INSTALL_DIR}/bin/php/php7.1.16/php7apache2_4.dll”
Note that the PHP version should be same as defined in the LoadModule php7_module path highlighted in red.

5. In the httpd.conf file, find the line similar to #Include conf/extra/httpd-mpm.conf and add the following lines below it.
# FCGI Configuration for PHP
Include conf/extra/httpd-fcgid.conf

6. Save and close httpd.conf.

7. Restart apache service and if everything went well, PHP should now be running with as FastCGI.

8. To verify that PHP is running as CGI/FastCGI and not as a module refer to the phpinfo. If the value of Server API is set to CGI/FastCGI that means PHP is running as a CGI and not as a module.
php info

Handling PHP Version Switching in WAMP to dynamically set VERSION_PHP in httpd.conf

1. Edit wampserver.lib.php in <wamp_directory>\scripts directory

2. In the function switchPhpVersion($newPhpVersion) find the line similar to $newHttpdContents .= 'AddModule ' . $phpConf['apache'][$apacheVersion]['AddModule'] . "\r\n"; and add the following lines below it.
elseif (strstr($line,'DEFINE') && strstr($line,'VERSION_PHP')) {
$newHttpdContents .= 'DEFINE VERSION_PHP '.$newPhpVersion."\r\n";
}

Finally, the code should look like this
handling php version
3. Save and close

4. Now when PHP version is switched in WAMP, the DEFINE VERSION_PHP variable will automatically update itself and FastCGI will use the required php-cgi.exe file according to the PHP version.

That is It!

 

CALL

USA408 365 4638

VISIT

1301 Shoreway Road, Suite 160,

Belmont, CA 94002

Contact us

Whether you are a large enterprise looking to augment your teams with experts resources or an SME looking to scale your business or a startup looking to build something.
We are your digital growth partner.

Tel: +1 408 365 4638
Support: +1 (408) 512 1812