You can configure the PHP script to stop if the connection closes, by ignore_user_abort(). But the script also has to send data periodically (every few seconds) and call flush() because only sending data will the closure be detected. See the link http://php.net/manual/en/function.ignore-user-abort.php that even has examples.
But in my opinion, it’s bad practice to change the server’s behavior depending on the client whether to keep the connection open or not. Exactly what you are trying to avoid -- a long or heavy processing, or a write-type side effect on the database?
Some heavy operations such as an SQL query that takes 40s (which should not take that long at all) will be executed atomically, that is, you will not be able to interrupt it in the middle, even using the technique suggested in the first paragraph.
It would be nice to know more details of this processing; seek to supplement the question so that we can supplement the answer.
The webservice php script on the server? My bet is that it won’t stop. It might stop but you shouldn’t count on it. The fact of not stopping results in a problem of lack of consistency between the client and the server whose path to solve passes by making the request of the script sure and/or idempotent: https://www.safaribooksonline.com/library/view/restful-web-services/9780596809140/ch01s04.html
– Piovezan