Can I set a query timeout when using Zend_Db_Adapter_Pdo_Mssql?

人盡茶涼 提交于 2019-12-13 14:51:37

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/16601140/can-i-set-a-query-timeout-when-using-zend-db-adapter-pdo-mssql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!