Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2013
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.38 KB | None | 0 0
  1. <?php
  2. foreach ( $Offers as $offer )
  3.         {
  4.             $localImages = array();
  5.             foreach( $offer->getOriginalImages() as $image )
  6.             {
  7.                 $pathParts = pathinfo( $image );
  8.                 $fileName = $pathParts['basename'];
  9.                 $webPath =  $photosDir . '/' . $offer->getCompany()->getId() . '/' . $offer->getId() . '/o/';
  10.                 $localDir = $webDir . $webPath;
  11.                 $localImage =  $localDir . $fileName;
  12.                 $webImage = $webPath . $fileName;
  13.  
  14.                 if ( ! is_dir( $localDir ) ) {
  15.                     mkdir( $localDir, 0777, TRUE );
  16.                 }
  17.                 try {
  18.                     $this->stopwatch->start( 'copy image' );
  19.                     $cp = copy( $image, $localImage );
  20.                     $event = $this->stopwatch->stop( 'copy image' );
  21.                     $periods = $event->getPeriods();
  22.                     $period = array_pop( $periods );
  23.                     echo 'copy:';
  24.                     var_dump( $period->getDuration() / 1000 );
  25.  
  26.                     $this->stopwatch->start( 'warmup cache' );
  27.                     $this->warmUpImageCache( $localImage, $webImage );
  28.                     $event = $this->stopwatch->stop( 'warmup cache' );
  29.                     $periods = $event->getPeriods();
  30.                     $period = array_pop( $periods );
  31.                     echo 'cache:';
  32.                     var_dump( $period->getDuration() / 1000 );
  33.                 }
  34.                 catch (\ErrorException $e) {
  35.                     var_dump( $e->getMessage() );
  36.                     $this->logger->error( sprintf( '%s : OfferId - %s', $e->getMessage(), $offer->getId() ) );
  37.                 }
  38.                 if ( $cp ) {
  39.                     $localImages[] = $webImage;
  40.                 }
  41.             }
  42.             $offer->setImages( $localImages );
  43.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement