title: PHP directory exist check problems
body: <p>I have a problem when I create a new directory with PHP when uploading a file.</p>
  
  <p>The directory is created, but if another instance of the same script runs at the same time the directory exist check doesn't work correctly (gives PHP warning).</p>
  
  <p>Someone told me it's a race condition but I still have this issue after adding some random sleep time.</p>
  
  <pre><code>usleep(mt_rand(1, 50));
  
  if(!is_dir($dir)){
    mkdir($dir);    
  }
  
  usleep(mt_rand(1, 50));
  </code></pre>
  
  <p>can anyone help?</p>
  
  <p>Does anybody know a safe way to upload a file in multiple parts, with 3-4 parts being uploaded at the same time? Currently I'm moving the uploaded parts in a temporary directory (is_dir fails on the temporary dir if more parts arrive at the same time), then when the number of files from that dir equal the number of parts the parts get combined. But it fails many times, sometimes is_dir gives warning, sometimes the parts get combined twice...</p>