我可以防止 PDO 中的长查询吗?

发布于 2024-08-03 00:50:16 字数 137 浏览 2 评论 0原文

如果查询时间太长,有没有办法让 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

做个少女永远怀春 2024-08-10 00:50:16

我不确定您所说的“这不是我可以在数据库中执行的操作”是什么意思,但我建议您让管理数据库的人员设置 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.

攀登最高峰 2024-08-10 00:50:16

我不确定您是否可以在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文