Re: [PHP] Re: Re: How to count transfered kBytes in File-Download



Michelle Konzack wrote:
Hello Eric,

Am 2009-01-04 14:33:37, schrieb Eric Butera:
On Sun, Jan 4, 2009 at 1:39 PM, Michelle Konzack
<linux4michelle@xxxxxxxxxxxxxxx> wrote:
----[ '/usr/share/tdphp-vserver/includes/02_functions.inc' ]------------
function fncPushBinary($type='show', $file, $mime='') {
<snip>
$BUFFER=1024;

$HANDLER=fopen($file, r);

$CUR_SIZE=0;
while ( !feof($HANDLER) ) {
$CUR_SIZE+=$BUFFER;
echo fread($HANDLER, $BUFFER);
}
fclose($HANDLER);

fncUserUpdate($user, 'downloads', $file, $CUR_SIZE, $FSIZE);
exit();
<snip>
}

function fncUserUpdate($user, $type, $file, $cur_size, $file_size) {
echo "What The Hell Is Going On Here?\n";
$HANDLER=fopen('/tmp/fncUserUpdate.log', a);
$DATE=date("r");
fwrite($HANDLER, "$DATE $user $file $cur_size $file_size\n");
fclose($HANDLER);
}
------------------------------------------------------------------------

Maybe a combination of ignore_user_abort & connection_status will get
you what you need. This way the user doesn't make the script die, but
you can keep checking to make sure the connection is active. If not,
update that db and exit out. I've never attempted anything like this,
so I don't really have any concrete answers for you.

Since I have encountered that fncUserUpdate() is writing the Test-Logfile
(even with wrong value) I am now puzzeling arround, because I was
thinking, if I am in the loop

while ( !feof($HANDLER) ) {
$CUR_SIZE+=$BUFFER;
echo fread($HANDLER, $BUFFER);
}

and the user intreeupt the transfer, the script would never reach

fncUserUpdate($user, 'downloads', $file, $CUR_SIZE, $FSIZE);

which WAS writing the Test-Logfile while beeing interrupted...

I have checked with phpsysinfo() but there are no settings like

ignore_user_abort
and
connection_status

The above two are functions, not settings.

Here are the links:
http://us.php.net/ignore_user_abort
http://us.php.net/connection_status


<SNIP>

function fncPushBinary($type='show', $file, $mime='') {

ignore_user_abort();

$BUFFER=1024;

$HANDLER=fopen($file, r);

$CUR_SIZE=0;
while ( !feof($HANDLER) ) {

# Check to see if the connection been aborted, or if it timed out.
# Plus, record the reason it was disconnected.
if ( ( $reason = connection_status() ) != CONNECTION_NORMAL ) {
RecordDownloadAmount($CUR_SIZE, $reason);
exit;
}


$CUR_SIZE+=$BUFFER;
echo fread($HANDLER, $BUFFER);
}
fclose($HANDLER);

fncUserUpdate($user, 'downloads', $file, $CUR_SIZE, $FSIZE);
exit();

}

</SNIP>

Something like the above should do the trick. Just create a function called RecordDownloadAmount() (call it whatever you want really) and have it log the information that you want stored about the download, then kill the script. should be that simple really...


Not I have replaced the fncUserUpdate() with the original function for
the PostgreSQL and MySQL database and it is just executed and the script
run up to the end... weird!

Thanks, Greetings and nice Day/Evening
Michelle Konzack
Systemadministrator
24V Electronic Engineer
Tamay Dogan Network
Debian GNU/Linux Consultant



.



Relevant Pages

  • Re: [PHP] How to count transfered kBytes in File-Download
    ... Michelle Konzack wrote: ... echo fread; ... "Some men are born to greatness, some achieve greatness, ...
    (php.general)
  • Re: [PHP] Re: How to count transfered kBytes in File-Download
    ... On Sun, Jan 4, 2009 at 1:39 PM, Michelle Konzack ... echo "What The Hell Is Going On Here?\n"; ... Debian GNU/Linux Consultant ...
    (php.general)
  • Re: [Full-disclosure] reduction of brute force login attempts via SSHthrough iptables --
    ... Anyhow its no problem at all to modify, so if you dont like it, just dont use it. ... on a lame script like this as long as it WORKS and is not insecure. ... echo "~ sorting out ip by ip" ... # echo "not enough failed logins, probably no attack from: ...
    (Full-Disclosure)
  • Re: Unix scripts
    ... operations at the beginning of the script while calling it after ... > If no file is given on the command line or all file lines were read, ... > The system calls echo and printf are frequently used for the file line ...
    (comp.unix.programmer)
  • Ripping Tapes with Linux--How To
    ... the full script is located in the BASH ... My tape player is a portable style journalist's recorder from the ... The most irritating part of the recording process was setting the ... echo Starting de-noise procedure to file $TMP1 ...
    (comp.os.linux.misc)