Is there any way to make a PDO object throw an error if a query takes too long? I have tried PDO::ATTR_TIMEOUT to no effect.
如果查询时间过长,有什么方法可以让PDO对象抛出错误吗?我尝试过PDO: ATTR_TIMEOUT但没有效果。
I'd like a way to have a query throw an error if it is running for longer than a certain amount of time. This is not something that I can do in the database, ie, no maintenance jobs running on the db or anything.
我希望有一种方法可以让查询抛出一个错误,如果它运行的时间超过一定的时间。这不是我在数据库中可以做的事情,例如,没有在db上运行的维护作业或其他任何东西。
2 个解决方案
#1
3
I'm not sure what you mean by "This is not something that I can do in the database", but I would suggest that you have the person administering the database set up an Oracle profile to limit this on the database side. There are parameters such as CPU_PER_CALL and LOGICAL_READS_PER_CALL that can cap queries. The profile can be applied only to specific users if desired.
我不确定您所说的“这不是我在数据库中可以做的事情”是什么意思,但我建议您让管理数据库的人设置一个Oracle概要,以在数据库端限制这一点。有一些参数,如CPU_PER_CALL和LOGICAL_READS_PER_CALL,可以限制查询。如果需要,这个概要文件只能应用于特定的用户。
#2
2
I'm not sure if you can do this in Oracle but I'm going to say it's not possible to do this within PHP since PHP is issuing the query to Oracle to be run and then is waiting for Oracle's response back. It may be possible to modify the PDO extension to support this, but you would need to modify the extension code (the actual C code) as there probably isn't any way to do this in just PHP.
我不确定在Oracle中是否可以这样做,但是我要说,在PHP中不可能这样做,因为PHP将向Oracle发出要运行的查询,然后等待Oracle的响应。可以修改PDO扩展来支持这一点,但是您需要修改扩展代码(实际的C代码),因为在PHP中可能没有任何方法可以做到这一点。
#1
3
I'm not sure what you mean by "This is not something that I can do in the database", but I would suggest that you have the person administering the database set up an Oracle profile to limit this on the database side. There are parameters such as CPU_PER_CALL and LOGICAL_READS_PER_CALL that can cap queries. The profile can be applied only to specific users if desired.
我不确定您所说的“这不是我在数据库中可以做的事情”是什么意思,但我建议您让管理数据库的人设置一个Oracle概要,以在数据库端限制这一点。有一些参数,如CPU_PER_CALL和LOGICAL_READS_PER_CALL,可以限制查询。如果需要,这个概要文件只能应用于特定的用户。
#2
2
I'm not sure if you can do this in Oracle but I'm going to say it's not possible to do this within PHP since PHP is issuing the query to Oracle to be run and then is waiting for Oracle's response back. It may be possible to modify the PDO extension to support this, but you would need to modify the extension code (the actual C code) as there probably isn't any way to do this in just PHP.
我不确定在Oracle中是否可以这样做,但是我要说,在PHP中不可能这样做,因为PHP将向Oracle发出要运行的查询,然后等待Oracle的响应。可以修改PDO扩展来支持这一点,但是您需要修改扩展代码(实际的C代码),因为在PHP中可能没有任何方法可以做到这一点。