fopen/fread php script works with apache but not litespeed

Discussion in 'General' started by Frees0ul, Feb 11, 2011.

  1. Frees0ul

    Frees0ul New Member

    Hey there, I have a script that fopens a remote url and then freads the content back to the browser. When I try it with litespeed, i'm downloading a file that is around 570Mb, however it seems to always cut off at around 520Mb so the transfer is never complete, when I switch from litespeed back to apache the full 570Mb downloads perfectly. I really want to stay with litespeed but if I can't get this fixed, then I'm going to have to switch back to apache, and I really don't want to do that, so here's me hoping someone here can help, maybe with a config setting or something

    Many Thanks in Advance :)

    Here's an extract from my php script:

    PHP:
    //setup headers for file transfer

    $fp fopen($remoteUrl'r'false$context);

    while (!
    feof($fp)) {
        print(
    fread($fp2048));
    }
    fclose($fp);
    Last edited: Feb 11, 2011
  2. mistwang

    mistwang LiteSpeed Staff

  3. Frees0ul

    Frees0ul New Member

    Hey there, I don't think it is the swap space, top reports:

    Swap: 8385920k total, 0k used, 8385920k free, 688156k cached

    I enabled debug logging on level high (that ok?), what should I be looking out for while I initate a transfer?

    LSAPI_MAX_PROCESS_TIME defaults at 300 seconds, the script runs for around 10 minutes or more (this is because I fread in chunks rather than all at once), so I don't think this is the issue.

    Max Dynamic Response Body Size was set at 500M, i've now set to 1024M and am testing the download out, I hold the most hope for this setting :)

    Thankyou
  4. Frees0ul

    Frees0ul New Member

    hmm, this time the transfer cut out at around 200Mb, any ideas?
  5. mistwang

    mistwang LiteSpeed Staff

    check the debug log, see why it is terminated.
  6. Frees0ul

    Frees0ul New Member

    Hey there, I think it worked this time, when I changed the Max Dynamic Response Body Size before I thought that it would automatically restart litespeed, I restarted manually and tried the download and it worked perfectly, i'm going to test again incase it was a fluke, but seems like that was the option that I needed to increase :)

    One other thing I noticed though, while initiating a transfer, I can't load php pages up on my website, if I do then the transfer slows way down and I cant access my website till I cancel the transfer.

    Any ideas on this?
  7. mistwang

    mistwang LiteSpeed Staff

    such large download takes too much valuable resources on PHP and disk I/O.
    Maybe you can try 4.1RC4 by changing the version number in the download link, it may do better than 4.0.x.
  8. Frees0ul

    Frees0ul New Member

    Hey there, thanks for reply, I think this is more of an ip restriction or something, I got 3 people to test the script which was downloading files over 500mb at the same time, none can access the website at the same time, but the script transfer flys by, meanwhile people from different ips can access the website, so maybe a setting to allow more than one connection to php per ip at a time or something?
  9. webizen

    webizen New Member

    Check your Per Client Throttling settings (Admin Console -> Configurations -> Server -> Security). Maybe your connection limit is low.
  10. Frees0ul

    Frees0ul New Member

    I think my connection limit is actually set too high, was at 10000 before, I brought the hard and soft limit down to 10.

    Also I just noticed, it wasn't actually the website that caused problems, it was when I initiated a download with my script and tried to access the litespeed admin panel at the same time that things mess up, so it's not as big of a deal, I can still access the website at the same time without problems. but just out of curiosity, any reaon this happens on accessing litespeed member panel?
  11. webizen

    webizen New Member

    Admin console is handled by a different litespeed server process and served on a different port (7080 by default). It is unlikely they interfere with each other. Do you have anything outside of Litespeed that limits per IP connection such as firewall, etc?
  12. Frees0ul

    Frees0ul New Member

    Hiya, It's probably something to do with the firewall, but not that important I think.

    The bigger concern for me right now is the reliablity of the script when running litespeed, sometimes the transfer goes through fine, other times it cuts out, whereas apache is always 100 percent reliable. Also I notice that apache will use around 20Mb per file transfer, whereas litespeed is using over 1Gb, I assume it is caching the entire download into memory rather than streaming at the speed of the client end; i'm sure there is some setting to disable this.

    Still, even though it is using 1Gb of ram there is still plenty of ram left over for me, so it still doesn't explain why the download cuts out. Maybe this is one of those cases where apache is the best option? considering the type of non-generic script I wish to run.
    Last edited: Feb 12, 2011
  13. Frees0ul

    Frees0ul New Member

    hmm, I went into the cache settings and switched all cache options off and then restarted lsws, but for some reason it's still caching the entire file into memory rather than streaming at client connection speed, same story with litespeed v4.1rc4 too :(
    Last edited: Feb 12, 2011
  14. webizen

    webizen New Member

    You may pm your script for further investigation.
  15. Frees0ul

    Frees0ul New Member

    thankyou, I have PM'd you my script :)
  16. mistwang

    mistwang LiteSpeed Staff

    Generally, with LiteSpeed, streaming large media file through PHP is a bad idea, as PHP run in their own process, LiteSpeed need to cache the response body to make PHP available for next request.
    LiteSpeed will cache the response in a temp file instead of in memory if the size of response body is known. Set "Content-length" header if you can.
    If the backend is a web server, try using "Proxy" instead of PHP.

    Apache with embedded PHP has advantage in this kind of application.
  17. Frees0ul

    Frees0ul New Member

    Thanks for the reply :) Is there anyway to replicate apaches embedded behaviour in litespeed with php, if so is there any benefit to using litespeed in this way over apache, considering litespeed is event driven over apache's threading?
  18. NiteWave

    NiteWave Administrator

Share This Page