Run a sql query with a timeout in PHP or How in PHP, to stop a sql query once already begun?

删除回忆录丶 提交于 2020-01-03 19:38:11

问题


I read the documentation for oci_cancel but it seems to me a bit fuzzy.

Does oci_cancel kill the sql process in the server?

If not, how can I make a script that executes a sql query, waits a moment and if the query exceeds 10 seconds (for example), cancel the query in the server?

Excuse me if this question is similar to one that has been asked time ago, but I didn't find any satisfactory answer.


回答1:


PDO allows you to specify the query timeout with the "ATTR_TIMEOUT" attribute, although it's entirely dependent whether the driver supports it or not.




回答2:


Eventually I had to use a solution that does not know if it's the best, but it was a mixture of things:

I was already using something like this to save the results of the querys in CSV files and then lift them into a session variable.

Well, I'm using this way to make a CSV file with the result of the query, sending the query by a PHP exec in background with a script in php with set_time_limit(10) and then waiting a time (10 seconds) until the result of the query has saved in a session variable. If the time(10 seconds) pass and I haven't got the query saved in the session variable I continue make the next actions.




回答3:


use set_time_limit if you want to cancel script execition and read this about oracle query cancelling



来源:https://stackoverflow.com/questions/8039075/run-a-sql-query-with-a-timeout-in-php-or-how-in-php-to-stop-a-sql-query-once-al

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