Setup:

Apache 2.26 webserver with PHP 5.2.5
Using MSSQL on a remote server.

I can connect and make MSSQL/PHP queries to the MSSQL database on the remote server - but after some time, APACHE/PHP comes back with 'Could Not Connect To Database' errors. Restarting Apache fixes the problem for a time, and then it starts again.

I am using the following settings in php.ini:

[MSSQL]
; Allow or prevent persistent links.
mssql.allow_persistent = On

; Maximum number of persistent links. -1 means no limit.
mssql.max_persistent = -1

; Maximum number of links (persistent+non persistent). -1 means no limit.
mssql.max_links = -1

; Minimum error severity to display.
mssql.min_error_severity = 10

; Minimum message severity to display.
mssql.min_message_severity = 10

; Compatibility mode with old versions of PHP 3.0.
mssql.compatability_mode = Off

; Connect timeout
mssql.connect_timeout = 120

; Query timeout
mssql.timeout = 120

; Valid range 0 - 2147483647. Default = 4096.
;mssql.textlimit = 4096

; Valid range 0 - 2147483647. Default = 4096.
;mssql.textsize = 4096

; Limits the number of records in each batch. 0 = all records in one batch.
;mssql.batchsize = 0

; Specify how datetime and datetim4 columns are returned
; On => Returns data converted to SQL server settings
; Off => Returns values as YYYY-MM-DD hh:mm:ss
;mssql.datetimeconvert = On

; Use NT authentication when connecting to the server
mssql.secure_connection = Off

; Specify max number of processes. -1 = library default
; msdlib defaults to 25
; FreeTDS defaults to 4096
mssql.max_procs = -1

; Specify client character set.
; If empty or not set the client charset from freetds.comf is used
; This is only used when compiled with FreeTDS
;mssql.charset = "ISO-8859-1"

Is there anything I need to change to avoid losing connectivity? BTW - this isn't a physical connectivity issue - connectivity between the two is not a problem.

Thanks

Ed

    Are you using persistent connections ([man]mssql_pconnect/man) in any of your applications?

      bradgrafelman wrote:

      Are you using persistent connections ([man]mssql_pconnect/man) in any of your applications?

      No.

      Ed

        Well so much for that easy fix. Still, you might disable persistent connections in your php.ini file (don't forget to restart the webserver and verify the change using phpinfo()!) and see if that clears it up (and incidentally turns up an application that uses _pconnect).

        Have you tried examining the Apache error logs around the time of the first failure for any clues?

          bradgrafelman wrote:

          Well so much for that easy fix. Still, you might disable persistent connections in your php.ini file (don't forget to restart the webserver and verify the change using phpinfo()!) and see if that clears it up (and incidentally turns up an application that uses _pconnect).

          Have you tried examining the Apache error logs around the time of the first failure for any clues?

          I disabled persistent connections and restarted Apache - and things seem to be stable. But this always happens after I restart Apache. I will see if it continues to work. There was nothing in the Apache log - and only an error that in couldn't connect in the PHP log - no reason.

          I will keep monitoring things - and will post back later today.

          Thanks

          Ed

            Also, visit [man]mssql_connect/man and read the user-contributed notes; you might try the suggestion given of updating the 'ntwdblib.dll' file located in the root of the PHP installation directory.

              bradgrafelman wrote:

              Also, visit [man]mssql_connect/man and read the user-contributed notes; you might try the suggestion given of updating the 'ntwdblib.dll' file located in the root of the PHP installation directory.

              Thanks.

              Already knew about the ntwdblib.dll issue. Actually, it doesn't work at all until you use the correct version of that file.

              So far it has been over 3 hrs and everything is stable. I am hoping just disabling persistent connections in PHP.INI did the trick.

              Thanks again.

              Ed

                Well.. that's odd; disabling that directive should not have had any effect unless an application on your server actually used persistent connections...

                  I thought so too, but there have been no errors, and all applications are working correctly.

                  Very strange.

                  If things remain ok, I'll mark the topic resolved later tonight.

                  Ed

                    Things have been stable - at least to the point where I don't lose connection to the remote database.

                    Now I just have to work on the speed problems - if a lot of people try to query at the same time, things really bog down.

                    Thanks for your help!

                    Ed

                      Write a Reply...