[英]Setting Connection Timeout Parameter in postgresql PDO connection
For some reason I want to set the postgresql connection timeout to 5 sec. 由于某种原因,我想将postgresql连接超时设置为5秒。 I am using the Zend Framework 1.12, And for creating the postgresql connection I am using the Zend_Db_Adapter_Pdo_Pgsql class, I did not found any parameter by which we can define the connection timeout.
我正在使用Zend Framework 1.12,并且为了创建postgresql连接,我正在使用Zend_Db_Adapter_Pdo_Pgsql类,但没有找到任何可用来定义连接超时的参数。
I search around but did not got anything for it. 我四处搜寻,但一无所获。 Please give me some suggestion how can I do it.
请给我一些建议,我该怎么做。
Thank You 谢谢
I found the solution: You need to set a timeout before each query: 我找到了解决方案:您需要在每个查询之前设置超时:
$db->beginTransaction();
$db->query('SET LOCAL statement_timeout = 2000'); //2 Sek. Timeout
$res = $db->fetchAll($select);
This only affects the NEXT Query to the DB and it's imporant that you have a Transaction. 这只会影响对数据库的NEXT查询,并且重要的是您有一个Transaction。 Without Transaction it won't work.
没有交易,它将无法正常工作。 If you made another Query after it (catch the timeout, rollback transaction), it will still have the default TIMEOUT.
如果您在之后执行另一个查询(捕获超时,回滚事务),则该查询仍将具有默认的TIMEOUT。 Creating a DB Routine will not work!
创建数据库例程将不起作用! You really have to set the timeout in your Function.
您确实必须在函数中设置超时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.