I'd like to know if there is a possibility to show server response as it send it in real time in a long time consuming request.
Context:
1) A Jquery function send an ajax request to the server and open a Dialog widget waiting for response to update Dialogs content.
2) The PHP server process the request in a long time consuming process, 20s, or much more up to minutes, it's an intranet website the user knows thongs takes time, lots of stuff to manage.
While the server is working, I have several "echo" in my PHP code with some stuff to say and the server is still working on other things to "echo" more.
My problem is that the Dialog don't updates as long as the server has not finished.
I want to show the partial response in live as soon as the browser receives it, with a SINGLE Ajax call from a unique function.
So... Two questions in fact:
Is my browser receiving the "echo" in live?
If Yes: How do I Show it live?
If No: How do I send it Live? And how do I Show it Live?
Any help would be greatly appreciated.
Thanks
Is my browser receiving the "echo" in live?
No, ajax waits for php to finish and then throws out all echoes at once.
If No: How do I send it Live? And how do I Show it Live?
I dont know a quick way to show it live but there are workarounds.
Create multiple ajax functions that will interact with the server to make it seem live. like I said in the comments. With this I am assuming you know how ajax works.
//javascript
function f1(){
//call ajax to tell the server send a start response
}
//php
echo "<img src='loading.gif'>";
//or something like it.
//ajax function to make the server do the data.
function f2(){
//call ajax to tell the server to start and save data in a session
//Or something like it also set div to be changed to a hidden div.
}
//php
//run the required script. then echo a finished response that can be found by js.
//to make it seem extra live you can split this up in different parts.
//so you can show progress to the client side. like step 1 of 5 complete.
//ajax function 3 for finished
function f3(){
//tell server to echo results once f2 is finished;
}
//php
//echo results loaded from where you saved it.
//probably session, delete the session when finished.