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.
- 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
php-cgi.exe crashed for unknown reason which I have completely no idea what was happening.
After searching on the web, here is what I found:
- 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', );
- 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