fatemaker
fatemaker

Reputation: 83

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 page closing?

Upvotes: 3

Views: 2198

Answers (4)

Bryan Agee
Bryan Agee

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

cwallenpoole
cwallenpoole

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

Gedrox
Gedrox

Reputation: 3612

You could kill the process on the server.

Upvotes: 0

Paul Sonier
Paul Sonier

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

Related Questions