Q. About Best Way To Buffer/Force Download

Hey,

I apologize as the Q. title is a bit off. I am looking to find a universal browser solution to generate a ‘please wait’ message while a large dynamic file is being generated. Allow me to explain:

When trying to force a download of a dynamically generated zip file, I created a way to let customers know that their dynamic zip file is in the process of being generated and will be ready to download shortly. It takes a while to generate the file as it’s 100+ MB of music files.

With that said, I use the following code to create the ‘please wait’ message before their download link appears once the file is ready (the zip file).

Problem is, on Firefox the message DOES load when generating the zip file but in Safari it doesn’t. Below is the code. The question I have is what is the PROPER way to allow universal display of the ‘please wait’ message WHILE it downloads.

For Safari, the problem is the html file WILL NOT load until the download link is ready. How can one ensure the included html file loads WHILE the dynamic large zip file is being generated?

Here is the code I use:


 include("html/waiting_dl.html");
 
 flush(); 
 
 sleep(1); // this in cycle

By the way, I am open to completely changing HOW this entire thing works but this is the first time doing something like this so forgive me if this isn’t the best way.

Thanks and happy new year, guys.

Interesting. If I add this it works in Safari:

echo str_pad(‘’,119096)."
";

I used that # as it’s greater than a suggested value of 9096 that I received from another board. I place this BEFORE the include html statement. So, for those struggling with creating a “Wait for download/load” type message, this was the solution for me.

I hope this helps!

Not really that interesting/strange.

The reason you might have different results in different browser, has to do with the output buffer. The environment the server is running does also matter, for example php and apache has two separate output buffer settings. This can mean, that even if you flushed the buffer from PHP, it is still not sent from the server as apache is still waiting to reach the limit set in its configuration.

In addition, as you noticed different browsers require different amount of “content” before they start rendering and showing content. When you pad the content, you basically fill the buffer with “spaces” and by that you manage to get enough content for the browser to start rendering.

The proper way, IMO, would be to display a plain ol’ HTML page which displays your ‘Please Wait’ message.

On this page, you would have a piece of JavaScript which fired off an AJAX request to the server to ask if the file is ready. If it is, invoke the download.

“The proper way, IMO, would be to display a plain ol’ HTML page which displays your ‘Please Wait’ message.”

Anthony>>But that’s the problem. I did and it never loaded in Safari while the file was loading. I am not sure how to confirm the file is generated via ajax, unless I am hitting it every few seconds to see if file exists. I guess that’s an idea. Is that what you refer to?

Thanks.

Are you using the same process to create the archive and this web page?

Yeah, it is all taking place on the same page. The code I posted lies directly above the zip file generator code.

Thank you.