title: PHP slow copy of files
body: <p>I have an issue that i can't resolve. I have a script which copy small image files. The problem is that for one image variant it gets about 1.5 seconds. Is there anything that can get it faster? I'm using PHP CLI and my HDD is WD VelociRaptor 10K RPM. The source folder contains about 200K files</p>
  
  <p>Here is the part of code i want to get faster:</p>
  
  <pre><code>        $startCopyVariant = time();
  
          $result = array('uploadedImagesUrls'=&gt;array(), 'errMsg'=&gt;'');
  
          // lazyload class instances
          $productOptionImages = &amp;lloader()-&gt;getImagesByName("productOption");
  
          // validate image
          $imgSizeInfo = @getimagesize($srcImageInfo['tmp_name']);
          if (empty($imgSizeInfo)) { $result['errMsg'] = 'Invalid image '.$srcImageInfo['name'].', type '.$srcImageInfo['type']; return $result; }
  
          $ext = pathinfo($srcImageInfo['name'], PATHINFO_EXTENSION);
  
          $variantFileName = 'opt_'.$optionId."_variant.".$ext;
          $mainDestFileName = $variantFileName;
          $srcFileName = $this-&gt;getCropSizeFileName($srcImageInfo['name'], "big");
          copy($srcFileName, $productOptionImages-&gt;getImagePath().$variantFileName);
  
          $variantFileName = $variantFileName = 'opt_'.$optionId."_variant_sma.".$ext;;
          $srcFileName = $this-&gt;getCropSizeFileName($srcImageInfo['name'], "small");
          copy($srcFileName, $productOptionImages-&gt;getImagePath().$variantFileName);
  
          $variantFileName = 'opt_'.$optionId."_variant_thu.".$ext;;
          $srcFileName = $this-&gt;getCropSizeFileName($srcImageInfo['name'], "thumbnail");
          copy($srcFileName, $productOptionImages-&gt;getImagePath().$variantFileName);
  
          $variantFileName = 'opt_'.$optionId."_variant_tin.".$ext;;
          $srcFileName = $this-&gt;getCropSizeFileName($srcImageInfo['name'], "tiny");
          copy($srcFileName, $productOptionImages-&gt;getImagePath().$variantFileName);
  
          $endCopyVariant = time();
  
          $elapsedTime = $endCopyVariant - $startCopyVariant;
          print_r("Variant copy time:  (".$srcImageInfo['name']."): ".sprintf('%02d:%02d:%02d', ($elapsedTime/3600),($elapsedTime/60%60), $elapsedTime%60), 0);
  </code></pre>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT: Here is the getCropsizeFileName does:</strong> </p>
  
  <pre><code>private function getCropSizeFileName($srcFileName, $size) {
          global $sourceCropBasePath;
          $ext = pathinfo($srcFileName, PATHINFO_EXTENSION);
          $destFileNamePrefix = basename($srcFileName, ".".$ext);
          return $sourceCropBasePath.$destFileNamePrefix."_".$size.".".$ext;
      }
  </code></pre>
  
  <p>The result of timers of each copy line are:</p>
  
  <pre><code>Variant copy time1:  (0a46de43f73304469a38137bf3f43c32.jpg): 00:00:02
  Variant copy time2:  (0a46de43f73304469a38137bf3f43c32.jpg): 00:00:01
  Variant copy time3:  (0a46de43f73304469a38137bf3f43c32.jpg): 00:00:02
  Variant copy time4:  (0a46de43f73304469a38137bf3f43c32.jpg): 00:00:01
  </code></pre>