The following script is written. A large number of images are “pulled out” from the CMS directory, php means each one is cut off, the size is reduced and all this is placed in the temporary directory, the names of the pictures are randomly generated and this is then displayed on the page from the temporary folder. and it all starts over again. The question is - how will the script behave when it is simultaneously accessed, say 100 people, will the images be displayed correctly?

    2 answers 2

    how will the script behave while simultaneously accessing it, say 100 people, will images be displayed correctly?

    Naturally, no =) Images will be shuffled and others will be loaded.

    I suggest adding a folder to the path. That is, when handling:

    • folder $ dir = 'tmp /' is created. session_id ()
    • pictures are poured into it
    • conclusion

    But further tambourine (we do not know when the pictures will be displayed, maybe there is a dial-up). Options:

    1) output via img src = "data: [...]" and immediately delete (sad, like up to 4kb size)

    2) give a minute or two-etc time. Those. Something like this

    <? session_start(); $limit = 60 * 2; // 2 min $now = time(); foreach (scandir('tmp') as $dir) if (($dir != '.') && ($dir != '..') && is_dir('tmp/'.$dir)) { // сканим все папки list($time, $id) = explode('_', $dir, 2); // и если if ($now - $time > $limit) // возраст больше лимита rmdir_rec('tmp/'.$dir); // рекурсивно очищаем + удаляем, в гугл за функцией } $dirname = $now.'_'.session_id(); // в эту папку будем кидать картинки require 'main_script.php'; // основной скрипт ?> 

      But is not it easier in this case to display images through a script, on the principle of captcha? All the same, GD load - so although the file system will not need to touch.
      If it's not a secret, why all these cunning manipulations?

      • These manipulations had to be done in connection with the customer's request, according to which the photos should be displayed cropped and compressed. There was no time left for an ingenious solution, it had to be a cattle-cattle. In fact, in perspective, even the simultaneous access of 10 people to the script on this site is hardly possible. Nevertheless, I would like everything to work more or less stable. Can make a check of the size of the temporary folder and only after exceeding a certain limit, clear the entire directory? - Include
      • Then you can create a bunch of thumbnails, and then output them through a script, depending on the get parameter. The php script will always appear in the address of the picture, but the load on GD will almost disappear. - ling