我可以防止 PDO 中的长查询吗?
如果查询时间太长,有没有办法让 PDO 对象抛出错误?我尝试过 PDO::ATTR_TIMEOUT 没有效果。
我想要一种方法,让查询在运行时间超过一定时间时抛出错误。这不是我可以在数据库中执行的操作,即数据库上没有运行任何维护作业或任何操作。
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定您所说的“这不是我可以在数据库中执行的操作”是什么意思,但我建议您让管理数据库的人员设置 Oracle 配置文件以在数据库端限制此操作。 CPU_PER_CALL 和 LOGICAL_READS_PER_CALL 等参数可以限制查询。如果需要,该配置文件可以仅应用于特定用户。
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 中执行此操作,但我想说在 PHP 中不可能执行此操作,因为 PHP 向 Oracle 发出要运行的查询,然后等待 Oracle 的响应返回。可以修改 PDO 扩展来支持这一点,但您需要修改扩展代码(实际的 C 代码),因为仅在 PHP 中可能没有任何方法可以做到这一点。
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.