Prevent php-cgi.exe the FastCGI Process Exited Unexpectedly on Windows Servers running MS SQL and IIS

Microsoft only loves Microsoft products and always hates the others. Recently I am working on a website using CakePHP. We are using the IIS, PHP, MS SQL configuration and well, things are just getting ugly when PHP access MS SQL database via PDO.

Environment:

  • Windows Server 2012 R2
  • IIS 8.5
  • PHP 5.4 installed via Microsoft Web Platform Installer
  • Microsoft SQL Server 2012
  • CakePHP 2.4 using PDO to connect to MS SQL

Problem:

php-cgi.exe crashed for unknown reason which I have completely no idea what was happening.

php-cgi.exe exited unexpectedly

My Solution

After searching on the web, here is what I found:

  1. If php-cgi.exe crashed randomly (and actually alternatively), it is possible that you have turned on persistent connection. According to this post, accessing MS SQL using PDO doesn’t like persistent connection. So just disabled the default on persistent connection in your CakePHP database configuration file.
        public $default = array(
            'datasource' => 'Database/Sqlserver',
            // Persistent connection should not be turned on for MS SQL as it will cause FastCGI to crash
            // https://github.com/cakephp/cakephp/issues/2003
            'persistent' => false,
            'host' => 'localhost',
            'login' => '',
            'password' => '',
            'database' => 'mydb',
            'prefix' => '',
            //'encoding' => 'utf8',
        );
  2. If php-cgi.exe crashed at a particular page, it is easier to trace what’s wrong but still you may not able to find a workaround. In my case, I tried to run stored procedures and php-cgi.exe just crashed by that time! For my case, I just have to use SET NOCOUNT ON to workaround the crash.
    CREATE PROCEDURE [dbo].[sp_my_proc]
    AS
    BEGIN
        SET NOCOUNT ON;
        -- ...
        -- Your code
        -- ...
    END
Advertisements

One response to “Prevent php-cgi.exe the FastCGI Process Exited Unexpectedly on Windows Servers running MS SQL and IIS

  1. if you have two application like (your app, phpmyadmin) just disable APC extension
    Hope that fix the issue
    it’s worked with me

    if not just install Microsoft visual C ++ 86 and 64

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s