How can I stop sql query execution in php?
I have a long SQL query execution. When I close the browser page, sql query (postgresql) execution continues. How can I stop it executing on pag开发者_开发知识库e closing?
Well, you can't guarantee that there is a disconnect without JavaScript and the only real way to ensure that you know that the window has closed is to have it continually ping the server -- sometimes the page closing events don't fire. So you'd basically need something in the background tracking the pings and if one does not fire in a given time, call the kill process.
As far as I know, it is not possible to tell a PostgreSQL connection without signing in as an admin and actually forcing the threat to close. The method is called pg_cancel_backend. I WOULD NOT forcibly terminate the process with the command line kill. That could have repercussions which can be avoided by using built in tools.
You'll have to have some javascript that'll pick up on the page close, and perform a postback to the server that will connect to the executing process and stop it.
You could kill the process on the server.
From the sound of your question, I'm guessing this is a development machine. If that is the case, just restart the web-server to terminate the php script. If you are using apache, that would look like:
sudo apache2ctl restart
精彩评论