php sense that user has quit downloading

Discussion in 'PHP' started by kc8yds, Jul 16, 2009.

  1. kc8yds

    kc8yds Active Member

    any way for php to sense that the user is no longer downloading a file / connected with litespeed?

    if a user leaves a page php will just keep processing and in my application this is a waste as it is a common occurrence
  2. auser

    auser Super Moderator

    how about php session?
  3. kc8yds

    kc8yds Active Member

    i do not think there would be anyway with a php session

    "$ch = curl_init(base64_decode($_GET['url']));
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);

    is the idea i am using (shortened it to make it easy to understand in the forums)

    it is downloading and sending to the user a flv file located on youtube servers (directed to people in china/iran/turkey (places youtube is blocked)

    when someone starts a video then moves away from the page php will keep running and download the entire file wasting incoming bandwidth and cpu time

    if need by i can do fopen -- read 50000 bytes at a time -- check if the user is still connected then transfer the next amount -- but i need a if/else statement to check and see if the person is still connected or not)

    this is causing a huge slowdown on the server if say someone only watches a few seconds of the video then moves to the next- -and does this repeatedly -- quickly adds up
    Last edited: Jul 16, 2009
  4. auser

    auser Super Moderator

    so it looks you're writing a php script to act as "flv proxy" between youtube and client. out of my knowledge :( however your request become clear.

    I think need know the detail steps how web server(here lsws) steam .flv to client.

    I guess flash player(at client side) request range download from web server. for example, download No. 1000 bytes to 2000 bytes of .flv file, No. 2000 to No.3000 bytes...etc. until the end of .flv. if that's the case, you can only request same range download from youtube, not the whole .flv file. No request from the client, no request from your script to youtube server. this will have no problem you described. --- just guess. FYI only.
  5. mistwang

    mistwang LiteSpeed Staff

    LSWS want to have PHP run as fast as possible. however, if the result of PHP processing was discarded, it will causes some waste in resource.

    There is no good solution on LSWS side, as PHP run out of LSWS process only connected with a socket connection.

    I am not sure your code fetch the whole content back then start the play back? or start play back as early as data is available.

    If it is the former. you need to change your code, it is too inefficient for large media file.

    If it is the later case, you can apply some bandwidth throttling policy in PHP, say, fetch the first xxxKB as fast as it can, then thottle it at certain bandwidth cap like 100KB/s, which is just a little bit faster than bandwidth need to play the video smoothly.

    LSWS buffer the response, you cannot rely on LSWS to cap the bandwidth for PHP.

Share This Page