PHP Readfile() number of bytes when user aborted

Posted by jtnire on Stack Overflow See other posts from Stack Overflow or by jtnire
Published on 2010-12-26T02:11:43Z Indexed on 2010/12/26 2:54 UTC
Read the original article Hit count: 215

Filed under:

Hi Everyone,

I'm using a PHP script to stream a live video (i.e. a file which never ends) from a remote source. The output is viewed in VLC, not a web browser. I need to keep a count of the number of bytes transferred. Here is my code:

<?php

ignore_user_abort(true);
$stream = $_GET['stream'];

if($stream == "vid1")
{
    $count = readfile('http://127.0.0.1:8080/');
    logThis($count);
}

function logThis($c)
{
    $myFile = "bytecount.txt";
    $handle = fopen($myFile,'a');
    fwrite($handle,"Count: " . $c . "\n");
    fclose($handle);
}

?>

However it appears that when the user presses the stop button, logThis() is never called, even though I've put in ignore_user_abort(true);

Any ideas on what I'm doing wrong?

Thanks

© Stack Overflow or respective owner

Related posts about php