How can I donwload many files with php without the server getting confused?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anagpino
    New Member
    • Mar 2011
    • 3

    How can I donwload many files with php without the server getting confused?

    I need to download many files at the same time per client using php.

    The files are images or xmls that the system uses to show content.

    I need to use php because the system needs to test that the user is logged in to return those files (they will be put in an htaccess, .htpasswrd protected folder).

    I am doing this using readfile. In my local server I have no problems but when I upload it to the company server and I stress test it (requesting files rapidly and/or from different clients) the server starts returning the same file instead of the different files that are being requested. Example client one ask for files 1,2,3,4,5 and client two asks for files 6,7,8 and client one ends up receiving files 1,2,3,2,2.

    The server is a shared server so I can not install mod_xsendfile.

    Is there any possible solution with php?

    Here is the code:
    Code:
    $ext = pathinfo($url, PATHINFO_EXTENSION);
    if(file_exists($url)){
    			
    	switch (strtolower($ext)){
    	    case "swf":
    	    	header("Content-type: application/x-shockwave-flash");
    	        break;
    	    case "jpg":
    	    case "jpeg":
    	        header('Content-Type: image/jpeg');
    	        break;
    	    case "gif":
    	        header('Content-Type: image/gif');
    	        break;
    	    case "png":
    	        header('Content-Type: image/png');
    	        break;
    	    case "flv":
    	    	header("Content-Type: video/x-flv");
    	    	break;
    	    case "xml":
    	        header('Content-Type: text/xml');
    	        break;
    	    case "css":
    	    	header("Content-type: text/css");
    	    	break;
    	    default:
    	    	echo("Error");
    	    	die();
    	}
    	header("Content-Length: " . filesize($url));
    	readfile($url);
    	die();
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    I would suspect a time-lag problem from bandwidth/browser rendering.
    Maybe readfile is not suitable here.
    I don't have experience of this but maybe streaming?

    Comment

    • anagpino
      New Member
      • Mar 2011
      • 3

      #3
      Thank you for your input. Unfortunately, I do not think that streaming would be possible to implement because of the characteristics of the system.

      A little bit more info:
      I am using Zend Framework.

      The file that tends to be repeated is usually one of the biggest ones (in the case of the example above the client one is requesting files 1,2,3,4,5. It gets 1,2,3,2,2. The file 2 is usually one of the biggest ones.
      There is also a problem that if client two asked for files 6,7,8 it might also get files requested by client one, for example files 6,2,2.

      Could the problem be in the buffering?

      Comment

      • anagpino
        New Member
        • Mar 2011
        • 3

        #4
        After some more testing I think that the problem is in the Zend Framework that the php code relies on. Because by getting out of the system I could find no problem loading the files.

        Comment

        Working...