Jump to content

Recommended Posts

Hello,

 

I need to make somehow, some system, to track whether downloads are completed or failed. I tried to make this via php.

 

Tried to limit the connection speed for smaller downloads (to have the time to detect a cancel) (+ ignore_user_abort(true)) in a while where i also checked the connection_status.

 

/* dl headers */

ignore_user_abort(true);

while(feof($f))

{

echo fread($f,5*1024); /* 5 kb/s */

flush();

sleep(1);

if (connection_status()!=0)

exit();

}

/* track after the download */

 

Well it doesn't work because the browsers are waiting for script execution to end before popping-up the download dialog. So the users waits like 20-30 seconds, then the download dialog pops, and instantly saves the file.

 

So, probably the only solution is something to intermediate the download. If you know some Java/../.. component which can do this (no matter free or payed) would be nice. :)

 

Or maybe, somebody knows a way to do this from php.

 

 

Thank you,

Aris.

Link to comment
https://forums.phpfreaks.com/topic/186138-track-downloads-status/
Share on other sites

are you just using this for bandwidth throttling?

Nope, I'm trying to see if the download is completed or not... if the feof == true happens or if meantime the connection is lost (connection_status() ). I am using sleep(1)... because i think that if i write everything in one shot, it gets sent to the user (no matter his bandwidth) and the scripts ends instantly, this making impossible to track if the user has actually received the entire file.

 

But it seems (at least in my implementation), that the "download file" dialog doesn't pop-up until the script ends. It just waits for the script, and at the same time gets the file; when the script ends, the pop-up appears and if you choose to save the file, it is saved instantly (because it was already downloaded). So it downloads the file in the background.. while the page is loading...

This is my understanding of php.

 

PHP, Hypertext Pre-Processor.

This means that php processes information before it reaches the browser, in fact, before it reaches apache (which sends the result to the browser).

 

So you cannot send output to the browser before the script has ended, and php reads the whole script at once, and sends it only after execution has ended.

 

--

 

I believe your only option is to use a browser-run scripting language, (that runs on the local browser, rather than the server), this would be in something similar to javascript, or flash.

 

You could use PHP, to set up the javascript. I just dont think there is even a way for apache to know if the download was successfull. And if apache doesnt know, then im sure php wont know :P.

 

-Good Luck though, if u find an easy answer please tell me ;).

-CB-

Upon browsing the php manual i came across a function called "flush()".

 

This nifty little function will output to the browser immediately (though there are specific buffering restrictions on specific versions of specific browsers).

 

There are a few things that will stop it from working properly, i suggest you take a long look at http://www.php.net/flush

 

Good Luck

-CB-

Upon browsing the php manual i came across a function called "flush()".

 

This nifty little function will output to the browser immediately (though there are specific buffering restrictions on specific versions of specific browsers).

 

There are a few things that will stop it from working properly, i suggest you take a long look at http://www.php.net/flush

 

Good Luck

-CB-

 

You may still have issues with your web server buffering output. If you've turned something like gzip encoding on, the web server will buffer it regardless of your usage of flush().

It's impossible to track whether a remote client completed a download. PHP is just a process that is controlled by the server, unless you write your own socket daemon with PHP. Even the server can not detect a completed download. It can only record the number of bytes that were handed off to the client.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.