SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Aug 2005
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    no simultaneous file downloads from the same browser

    Hi,
    I have the following simple code that forces a file download, my problem is that if I call the script two or more times from the same browser the second download won't start until the first is completed or interrupted. Thus I can download only one file per time.
    Do you have any clue?

    Code:
    <?php
    
    $filename= './get/me/me_'.rand(1,100).'.zip';
    
    header("Content-Length: " . filesize($filename));
    header('Content-Type: application/zip');
    header('Content-Disposition: attachment; filename=foo.zip');
    
    readfile($filename);
    ?>

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm going to borrow rudys magic crystal ball...hold on...are you using native php sessions?

  3. #3
    SitePoint Member
    Join Date
    Aug 2005
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've never touched anything that came out from the standard ubuntu server installation.
    So the anwser is: maybe yes.
    What's the big deal with native sessions?

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The default files session handler acquires an exclusive lock on the session file, so only a single instance of a php script can access a given session at any moment in time(a good thing).

    But, that means that if you have a script that must run for a long time, a user cannot access any other pages that also use that session until the first one finishes(or until you call session_write_close()).

    php does have a session.auto_start option, although I'd be real surprised if php came with that turned on as a default setting. Otherwise, you would need to have manually called session_start() somewhere.

    Another possibility is the web server is limiting connections to one at a time. Your browser could do it too, but they usually allow 2 or more connections per domain.

  5. #5
    SitePoint Member
    Join Date
    Aug 2005
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks crmalibu,
    I've some news. The second download starts about one minute later the first, whether if I close session or not before outputting the file. So concurrent downloads are actually possible but with a delay.
    I really don't understand...

  6. #6
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you absolutely verified no session is active for that request? You can check by inspecting the value of session_id() right before that code.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •