Reputation: 83
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 page closing?
Upvotes: 3
Views: 2198
Reputation: 5052
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
Upvotes: 0
Reputation: 82028
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.
Upvotes: 2
Reputation: 39480
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.
Upvotes: 1