THis is something that I have been experiencing often. I am running a PHP script to insert data into a PostGreSql database. Now sometimes, if I stop this script execution in the middle, somehow the data still keeps getting added to the database.
Why is this happening and how do I circumvent this problem?
Note that just pressing “stop” in your browser doesn’t actually stop the PHP script (not on most servers anyway), it will just disconnect the browser from further output. The script will keep running on the server until it completes or times out.
Restarting the server will shut down any scripts running there, but that’s like trying to kill a fly with a cannon.
In the simplest case, you may want to check for
!connection_aborted()every now and then. See http://php.net/manual/en/features.connection-handling.php