arisro Posted December 23, 2009 Share Posted December 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/186138-track-downloads-status/ Share on other sites More sharing options...
Virvo Posted December 23, 2009 Share Posted December 23, 2009 are you just using this for bandwidth throttling? Quote Link to comment https://forums.phpfreaks.com/topic/186138-track-downloads-status/#findComment-983087 Share on other sites More sharing options...
arisro Posted December 23, 2009 Author Share Posted December 23, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/186138-track-downloads-status/#findComment-983212 Share on other sites More sharing options...
ChemicalBliss Posted December 23, 2009 Share Posted December 23, 2009 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 . -Good Luck though, if u find an easy answer please tell me . -CB- Quote Link to comment https://forums.phpfreaks.com/topic/186138-track-downloads-status/#findComment-983218 Share on other sites More sharing options...
ChemicalBliss Posted December 24, 2009 Share Posted December 24, 2009 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- Quote Link to comment https://forums.phpfreaks.com/topic/186138-track-downloads-status/#findComment-983611 Share on other sites More sharing options...
Daniel0 Posted December 24, 2009 Share Posted December 24, 2009 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(). Quote Link to comment https://forums.phpfreaks.com/topic/186138-track-downloads-status/#findComment-983707 Share on other sites More sharing options...
ChemicalBliss Posted December 24, 2009 Share Posted December 24, 2009 Exactly, not only that but there are numerous things that can prevent it, which is why i strongly reccommend thoroughly reading the comments from "http://php.net/flush". Too many to mention here in detail. -CB- Quote Link to comment https://forums.phpfreaks.com/topic/186138-track-downloads-status/#findComment-983749 Share on other sites More sharing options...
printf Posted December 24, 2009 Share Posted December 24, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/186138-track-downloads-status/#findComment-983830 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.