How to Configure FastCGI on WAMP
blog-page-header-bg

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.

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

Latest From Our Blog

Deploying NodeJs (ExpressJs) project with Docke...

May 20, 2019
Prerequisites: Nodejs understanding, Kubernetes/Docker Architecture Theory We are going to learn how to: Deploy an expressjs app (docker image) to ...
Read more

How to Manage Multiple Environments in a React ...

May 16, 2019
This is a step by step guide for React Native Developers to understand how to manage multiple environments in a React Native App for Android. Envir...
Read more

React.js to React Native, Kickstart!

May 6, 2019
Do you know React.js and want to learn React Native or need some Kickstart Introduction of React Native? Then this is where this blog comes in to g...
Read more