How to make PHP abort on page in relation to the AJAX request?

Good day
There is a PHP page is an AJAX request
Is it possible in the middle of a PHP script to mimic the end of a page (i.e. a response is sent back to an AJAX request, for it is as if PHP has worked), but in fact PHP will be executed next?
July 2nd 19 at 17:42
2 answers
July 2nd 19 at 17:44
Solution
php.net/manual/ru/function.ob-start.php and all that is connected with the output buffer
July 2nd 19 at 17:46
Solution
Actually, the script will work as long as not executed completely or until it reaches the max_execution_time parameter (in php.ini), usually it is 30 seconds, but with access to php.ini you can set this time up to infinity. If running PHP from the console - this option has no effect, but that's not the case. And what do you mean by "end of page" - nothing more than resetting the buffer, but do not forget that a web server can have its own buffer, which may also have to configure what the server does not "hang" waiting.

That is, this algorithm, you start a script, as a result of the AJAX request is sent to the output data You need (using print/echo), when the last batch of data sent - make flush(), and... the script continues to work on.

Also, the buffer is automatically cleared (sent to the browser and/or intermediate server) at the end of the script, that's why "end of script" do You associate with the "end page".
And is there a way to prevent echo and print_r after flush()?
And then there are several functions which in the case of what is immediately given a message by the echo... - rigoberto commented on July 2nd 19 at 17:49
I "immediately" to do so could not, I think, even if the functionality of clearing the buffer from content provided - at the first overflow, it will automatically reset to the browser before we have time to clean. According to this, safer to just comment out the line with echo (this is the easiest option), or to redirect their output to a file for logging, if this message is critically important. - Salvado commented on July 2nd 19 at 17:52
: no, not at all important
But the function "standard"
You can not change them...
And the damn echo causes an error AJAX'and - rigoberto commented on July 2nd 19 at 17:55
: try this:
ob_start(function() {});
print 111;


helped me like... - Salvado commented on July 2nd 19 at 17:58
after the line ob_start(function() {}); the output echo/print will be displayed in "nowhere". Should work like, but in battle mode I didn't test until this is not possible. - Salvado commented on July 2nd 19 at 18:01
: thanks, works! - rigoberto commented on July 2nd 19 at 18:04

Find more questions by tags PHP