omdeshpande Posted August 2, 2013 Share Posted August 2, 2013 I'm writing a file upload script using the iframe method. At the backend, post file upload, the script does a few more things. So I'm flushing output to the browser (which goes to the iframe) as soon as the file is uploaded and then the script continues. From the Chrome console I can see that the response has been received by the browser (200 OK), but, for some reason the browser only renders it after the entire script has finished, causing quite a long delay. Why is this happening? How can I get the browser to render it immediately? I have read a number of articles, blogs and Q/A on this topic that gave me the following hints, but none of them seem to be working: - Some browsers require a minimum number of bytes to start rendering (256/1024/4096). - If closing tags are missing, browsers tend to wait for it before they start rendering. - Content length is required, otherwise the browser may be keep waiting for more data. I have the above covered, I'm I missing something else? Backend code:$r = " <!DOCTYPE html> <head> <title></title> </head> <body> <p id='response'>$response</p> <p>".str_repeat(".", 4096)."</p> </body> </html>";ignore_user_abort(true);set_time_limit(0);ob_end_clean();ob_start();echo $r;header("Content-Length: ".ob_get_length());header("Connection: close", true);header("Content-Encoding: none");ob_end_flush();flush();Frontend code:var iframe = document.getElementById("uploaddocframe_" + aid);var iframeobj = (iframe.contentWindow || iframe.contentDocument);if(iframeobj.document) { var iframedocument = iframeobj.document; var response = iframedocument.getElementById("response").innerHTML; if(response == "success"){ //Do something } else { // Do something }} Quote Link to comment https://forums.phpfreaks.com/topic/280762-browser-isnt-rendering-ob_flush-output-immediately/ Share on other sites More sharing options...
lemmin Posted August 2, 2013 Share Posted August 2, 2013 Have you tried other browsers? I think the problem you are having is stemming from how the browser handles iframes specifically. My suggestion is to switch to AJAX for this kind of thing. Quote Link to comment https://forums.phpfreaks.com/topic/280762-browser-isnt-rendering-ob_flush-output-immediately/#findComment-1443213 Share on other sites More sharing options...
Solution omdeshpande Posted August 4, 2013 Author Solution Share Posted August 4, 2013 Yeah, I gave up on this method. AJAX isn't an option, because of data security. I solved this with a completely different approach. I implemented a "parallel processing via divide and rule" algorithm. More complex to implement, but much more stable and reliable. Post resume upload, I forked the code and deviated the tasks, post document upload, to another URL and then flushed that request immediately. Thereby, taking the browser out of the equation. Quote Link to comment https://forums.phpfreaks.com/topic/280762-browser-isnt-rendering-ob_flush-output-immediately/#findComment-1443400 Share on other sites More sharing options...
omdeshpande Posted August 4, 2013 Author Share Posted August 4, 2013 Yeah, I gave up on this method. AJAX isn't an option, because of data security. I solved this with a completely different approach. I implemented a "parallel processing via divide and rule" algorithm. More complex to implement, but much more stable and reliable. Post resume upload, I forked the code and deviated the tasks, post document upload, to another URL and then flushed that request immediately. Thereby, taking the browser out of the equation. Quote Link to comment https://forums.phpfreaks.com/topic/280762-browser-isnt-rendering-ob_flush-output-immediately/#findComment-1443401 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.