Suitable technology for handling a large number of file downloads

I work on a site that receives about 500 photos a day from its users. Although this is not a very large number, we are faced with some collisions between different downloads. Some users reported seeing a thumbnail of another image, not the one they downloaded. I was looking for an explanation of this problem, and I found a couple of questions in stackoverflow:

PHP temp file names for download crashes

Download PHP files from under "hijacked" by partial download

As I read, the problem seems to be due to a collision in the tmp file name. To avoid this, we considered changing the upload_tmp_dirPHP variable depending on an integer calculated from the registered username to reduce the chance of a collision. However, this variable cannot be changed at run time, because when PHP starts to execute, the file is already sent to the server.

I am not sure how to solve this problem, and I would like to fix it to prevent future problems if the daily download speed continues to increase.

There are many sites that handle large volumes of downloads, so I'm wondering how to avoid this conflict issue. The site I work on runs on PHP 5.2.14. I would prefer a PHP solution for simplicity, but I am also interested in existing solutions using other scripting languages ​​if they ensure that there are no collisions between downloads.

+3
source share
1 answer

The problem may also be in your DBlogic. A safe way is to insert a row in the database, get the primary key of your record. Using this number as the file name will prevent conflicts. You can do something like:

LOCK TABLES image WRITE;
INSERT INTO image (id) VALUES (NULL);
SELECT LAST_INSERT_ID();
UNLOCK TABLES;

(auto_increment) id. (, ) , .

+1

All Articles