PHP/PDO:Mysql query proccess still running after browser closing

I basically have a php script connecting to a pdo:mysql database which executes some time-consuming loop.
All works fine, unless the query is still running on the server side, updating infinitly, even after browser closed. I have to kill the mysql proccess (sleep) to stop it.

$time_start = microtime(true);
	while(true){
		$time_end = microtime(true);
		$time = $time_end - $time_start;
		if($time > 0){
			$hours = floor($time / 3600); 
			$minutes = floor($time % 3600 / 60); 
			$seconds = $time % 60; 
			$et = sprintf("%d:%02d:%02d", $hours, $minutes, $seconds);
			//echo $et;
			$temail->set('read_time', $et); //  last updated time to db 
			$temail->save(); // save
			sleep(1);
        }
		//ob_flush();
		//flush();
	}

How can I stop the query persistence running even after browser closing?
Any ideas?

btw:sorry 4 my english.

That is only for complete transactions. Closing the browser or tab completely cancels that transaction with no goodbye. Its like hanging up the phone on someone.

Ofcourse…what other definition of infinity did you have in mind - in regards to developing for the web.

Running a while loop with a true argument, is probably not the best way… just my $0.02.

Not necessarily… true is true only before user closes the browser

It seems that the problem is related to behavior or connection through PDO, because when I connect directly to mysql everything works fine.

That’s normal for a TCP/IP connection. When the server sends a packet and it reaches the client and if the connection has been closed by the client, it will send a packet back stating it.

Solved!

“The STOP button discovery (and so script abortion) worked only in case script was outputing something. If script is just doing something like scripts or MySQL calls and does not output anything to the browser neither automatic termination not connection_aborted() check seems to work. More over you need both ob_flush() and flush() together with IO for it to work reliably as if no low level network send is attempted connection abort from client will not be discovered.”

Quote source: http://www.mysqlperformanceblog.com/2008/05/20/apache-php-mysql-and-runaway-scripts/ #4
:lol:

while(true) what the hell?

Ofcourse its running infinity, true will always be that - true.

You’re talking about a PDO query, but you have not provided one in your code?

Not necessarily… true is true only before user closes the browser
How did the looping php script running on the server find out the browser was closed?