Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can PHP tell when the browser goes away?

Tags:

php

If I'm generating a stream of data to send out to a browser, and the user closes the browser, can I tell within PHP that I don't need to bother generating or sending the rest of the stream? I'd like to insert something into this loop:

while (!feof($pipes[1])) {
   echo fgets($pipes[1]);
}

My fallback plan is to have the browser use a JavaScript onunload to hit another PHP page to kill the process that's generating the data, but it would be cleaner if PHP could tell when I'm echoing to nowhere.

like image 361
Ross Morrissey Avatar asked Dec 17 '22 07:12

Ross Morrissey


1 Answers

By default PHP will abort the script if the user navigates away. There are however times where you don't want this to happen so php has a config you set called ignore_user_abort.
http://php.net/manual/en/misc.configuration.php

like image 188
Ballsacian1 Avatar answered Jan 25 '23 23:01

Ballsacian1