Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

We have a PHP application (hosted on Linux) which uses Zend Framework components to query a Microsoft SQL Server 2008 database. The PHP application is hosted in a datacenter with reliable internet connection, but the SQL Server database is at the far end of a VPN connection that drops out regularly.

The issue we have is that VPN drop outs occasionally occur while queries against the SQL server are in progress. When this occurs our application can wait up to 2 hours before finally raising the following exception:

SQLSTATE[HY000]: General error: 20004 Read from the server failed [20004] (severity 9) [(null)]

What I'd like to do is set an overall query timeout and/or read timeout of around 2-3 minutes so that the application gets an exception much earlier and con recover from it without blocking for 2 hours.

We're using the pdo_dblib extension to connect to SQL Server, and I've been through the php.net docs and I can't find any timeout options either for the connection of php.ini.

share|improve this question
    
Have you tried the PDO::ATTR_TIMEOUT attribute? – Kate May 17 '13 at 5:19
    
@Kate no, I haven't. I was looking for something driver specific and completely overlooked the PDO attributes. PDO::ATTR_TIMEOUT sounds like exactly what I wanted. If you want to post that ans an answer I'd be happy to accept it... Bonus points if you know what the default timeout is! – Jim OHalloran May 17 '13 at 5:54
up vote 1 down vote accepted

Try using the PDO::ATTR_TIMEOUT attribute. I'm not sure what the default value is for pdo_dblib, it may differ between the drivers.

share|improve this answer

PHP works with the Unix library FreeTDS which interacts with MSSQL/Sybase servers.

FreeTDS is an open-source implementation of the TDS (Tabular DataStream) database client access protocol and related libraries used by Sybase and Microsoft. FreeTDS supports all versions of the protocol from both vendors, and includes DB-Lib, CT-Lib, and ODBC libraries.

Settings for a timeout must be set therefore in the freetds.conf file.

Please see http://freetds.schemamania.org/userguide/freetdsconf.htm

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.