473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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:
Expand|Select|Wrap|Line Numbers
  1.  
  2. $ext = pathinfo($url, PATHINFO_EXTENSION);
  3. if(file_exists($url)){
  4.  
  5.     switch (strtolower($ext)){
  6.         case "swf":
  7.             header("Content-type: application/x-shockwave-flash");
  8.             break;
  9.         case "jpg":
  10.         case "jpeg":
  11.             header('Content-Type: image/jpeg');
  12.             break;
  13.         case "gif":
  14.             header('Content-Type: image/gif');
  15.             break;
  16.         case "png":
  17.             header('Content-Type: image/png');
  18.             break;
  19.         case "flv":
  20.             header("Content-Type: video/x-flv");
  21.             break;
  22.         case "xml":
  23.             header('Content-Type: text/xml');
  24.             break;
  25.         case "css":
  26.             header("Content-type: text/css");
  27.             break;
  28.         default:
  29.             echo("Error");
  30.             die();
  31.     }
  32.     header("Content-Length: " . filesize($url));
  33.     readfile($url);
  34.     die();
  35.  
Mar 17 '11 #1
3 1701
code green
1,726 Expert 1GB
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?
Mar 17 '11 #2
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?
Mar 18 '11 #3
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.
Mar 18 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Alexander Hoffmann | last post by:
Hello, I have a project with a number of python modules, which means there are several *.py files all in the same folder /usr/local/myproject/*.py . I ran the program to test it and of course as...
1
by: Green | last post by:
Hi, I had a question about how to copy files from server to server on the same LAN. Basically, i need to copy files from "develope server" to the "test server", then eventually to the "production...
4
by: Weston Weems | last post by:
I've got the simple problem where I'd like to transfer somewhat large files to my webserver via http/webservice/something like that. My question is what kinda limits have people been able to...
4
by: Navin Mishra | last post by:
Hi, Is it possible to host ASP.NET web services files without IIS ? Thanks in advance and regards Navin
1
by: joe | last post by:
Any articles relating with Uploading images files to server and resize the image by asp.net 2.0
6
by: laredotornado | last post by:
Hi, Is there a cross-browser way to play short (< 25K) sound files without spawning new windows or embedding any visual controls on the page? I would like to click a button and hear my short...
0
by: remya1000 | last post by:
how can i send a new file to a server using FTP in VB.NET. i need to try sending new files to server using FTP. after sending i can delete from server,rename,update the file etc. first i need...
8
by: VUNETdotUS | last post by:
My goal is to upload files without submitting the form. I am not looking for the code here but rather a concept. I did a little research and discovered that I can submit a form to an invisible...
1
inch
by: inch | last post by:
I would like to pop up a small information window (form) while my application is running to remind the user about something. However it should not get focus as this could intefere with what the user...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.