Reputation: 431
Is it possible to run a PHP script when the client is closing?
I want to send data to SQL when the user exits the site.
Is this possible to do or do i have to find another way a round this?
Upvotes: 0
Views: 33
Reputation: 12495
There is no reliable way - and can't be, as per how HTTP works. The error prone and unreliable ways (like setting up a companion websocket connection and acting when it closes or heavy polling) are very hard to build in PHP and would require special setup - since normally PHP scripts only run on requests (and there is no request when user exits site).
Upvotes: 1