I use AJAX to update some values ββin the database. Everything did a great job with this, but now I would like to implement some entries. The logging functions look like they are going to spend a lot of time processing, and they have no reason why the user will have to wait for them to finish in order to see their AJAX results.
So, I'm trying to find a way to send AJAX results and continue processing on the server side. My research has called the ignore_user_abort function, but apparently I am not using it correctly.
This guide is that I disabled my code.
Here is my javascript (jQuery):
$.ajax({ type: "GET", url: "ajax.php", data: { "mydata": mydata }, success: function(msg) { $("span#status").fadeOut(200, function() { $("span#status").html(msg); $("span#status").fadeIn(200); }); } });
And my PHP:
$response = "This is my response"; //Begin code from link ob_end_clean(); header("Connection: close"); ignore_user_abort(true); ob_start(); echo $response; header("Content-Length: " . mb_strlen($response)); ob_end_flush(); flush(); //End code from link echo "I should not see this text";
Unfortunately, I see this text after a flash ();
Any ideas?
Update - Bugfix: I found out my error. After copying the words into the tone of the various sentences of the code, I decided that this must be a mistake in my apache / php configuration. Turns out I need to add two lines in order to get apache not to buffer my results:
apache_setenv('no-gzip', 1); ini_set('zlib.output_compression', 0);
source share