Parallel script execution

The following script has been written.
A large number of images “escape” from the CMS directory, each is cut off using php, the size is reduced and all this is placed in a temporary directory, the names of the pictures are generated randomly and all this is then displayed on the page from the temporary folder, when the script is subsequently run, the temporary directory is completely cleared of files and everything starts anew. The question is – how will the script behave when simultaneously accessed by, say, 100 people, will images be displayed correctly?


Answer 1, authority 100%

how will the script behave when simultaneously accessed by, say, 100 people, will images be displayed correctly?

Of course not =) Images will be overwritten and others will be loaded.

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

  • folder $dir = ‘tmp/’.session_id()
  • is created

  • images are poured into it
  • output

And here is a 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-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'; //  
?>

Answer 2, authority 100%

Isn’t it easier in this case to display images through a script, according to the captcha principle? Anyway GD load – so although the file system will not need to be touched.
If it’s not a secret, why all these cunning manipulations?