コード例 #1
0
 /**
  *
  */
 public function run()
 {
     echo "ImagickTaskRunner started\n";
     /** @noinspection PhpUndefinedMethodInspection */
     \ImagickDemo\Imagick\functions::load();
     \ImagickDemo\ImagickDraw\functions::load();
     \ImagickDemo\ImagickPixel\functions::load();
     \ImagickDemo\ImagickKernel\functions::load();
     \ImagickDemo\ImagickPixelIterator\functions::load();
     \ImagickDemo\Tutorial\functions::load();
     $maxRunTime = 60;
     // one minute
     $maxRunTime *= 60;
     // 1hour
     // Each image generated hurries up the restart by 50 seconds
     // for a max of 72 images generated per run
     $taskPseudoTime = 50;
     $endTime = time() + $maxRunTime;
     $count = 0;
     while (time() < $endTime) {
         $task = $this->taskQueue->waitToAssignTask();
         if (!$task) {
             echo ".";
             $count = $count + 1;
             if ($count % 20 == 0) {
                 echo "\n";
             }
             //Sleep for 1/10th of a second
             usleep(100000);
             continue;
         }
         echo "A task! " . "\n";
         $endTime -= $taskPseudoTime;
         try {
             $startTime = microtime(true);
             $this->execute($task);
             $time = microtime(true) - $startTime;
             $this->asyncStats->recordTime(self::EVENT_IMAGE_GENERATED, $time);
             echo "Task complete\n";
             $this->taskQueue->completeTask($task);
         } catch (\ImagickException $ie) {
             echo "ImagickException running the task: " . $ie->getMessage();
             $this->taskQueue->errorTask($task, get_class($ie) . ": " . $ie->getMessage());
         } catch (\Auryn\BadArgumentException $bae) {
             //Log failed job
             echo "BadArgumentException running the task: " . $bae->getMessage();
             $this->taskQueue->errorTask($task, get_class($bae) . ": " . $bae->getMessage());
         } catch (\Exception $e) {
             echo "Exception running the task: " . $e->getMessage();
             $this->taskQueue->errorTask($task, get_class($e) . ": " . $e->getMessage());
         }
     }
     echo "\nImagickTaskRunner exiting\n";
 }
コード例 #2
0
 /**
  *
  */
 public function run()
 {
     /** @noinspection PhpUndefinedMethodInspection */
     \ImagickDemo\Imagick\functions::load();
     \ImagickDemo\ImagickDraw\functions::load();
     \ImagickDemo\ImagickPixel\functions::load();
     \ImagickDemo\ImagickKernel\functions::load();
     \ImagickDemo\ImagickPixelIterator\functions::load();
     \ImagickDemo\Tutorial\functions::load();
     $executableList = [];
     $imageGenerateExecutable = new Executable([$this, 'actuallyRun']);
     $imageGenerateExecutable->setTierNumber(\Tier\TierCLIApp::TIER_LOOP);
     $imageGenerateExecutable->setAllowedToReturnNull(true);
     $executableList[] = $imageGenerateExecutable;
     $timeoutExecutable = new Executable([$this, 'timeoutCheck']);
     $timeoutExecutable->setTierNumber(\Tier\TierCLIApp::TIER_LOOP);
     $executableList[] = $timeoutExecutable;
     return $executableList;
 }
コード例 #3
0
ファイル: compare.php プロジェクト: sdmmember/Imagick-demos
<?php

require __DIR__ . '/../vendor/autoload.php';
//require __DIR__ . "../../imagick-demos.conf.php";
require __DIR__ . '/../src/bootstrap.php';
\ImagickDemo\Imagick\functions::load();
\ImagickDemo\ImagickDraw\functions::load();
\ImagickDemo\ImagickPixel\functions::load();
\ImagickDemo\ImagickPixelIterator\functions::load();
\ImagickDemo\Tutorial\functions::load();
function compareFile($injector, $functionFullname, $filename, $fileExtension)
{
    $newFilename = $filename . "new1";
    generateCompare($injector, $functionFullname, $newFilename);
    //echo "Comparing $filename to $newFilename \n";
    echo ".";
    $imagickSrc = new Imagick($filename . $fileExtension);
    $imagickNew = new Imagick($newFilename . $fileExtension);
    //    const LAYERMETHOD_UNDEFINED = 0;
    //    const LAYERMETHOD_COALESCE = 1;
    //    const LAYERMETHOD_COMPAREANY = 2;
    //    const LAYERMETHOD_COMPARECLEAR = 3;
    //    const LAYERMETHOD_COMPAREOVERLAY = 4;
    //    const LAYERMETHOD_DISPOSE = 5;
    //    const LAYERMETHOD_OPTIMIZE = 6;
    //    const LAYERMETHOD_OPTIMIZEPLUS = 8;
    //    const LAYERMETHOD_OPTIMIZETRANS = 9;
    //    const LAYERMETHOD_COMPOSITE = 12;
    //    const LAYERMETHOD_OPTIMIZEIMAGE = 7;
    //    const LAYERMETHOD_REMOVEDUPS = 10;
    //    const LAYERMETHOD_REMOVEZERO = 11;
コード例 #4
0
 /**
  *
  */
 public function run()
 {
     echo "ImagickTaskRunner started\n";
     \Imagick::setResourceLimit(\Imagick::RESOURCETYPE_TIME, 60);
     /** @noinspection PhpUndefinedMethodInspection */
     \ImagickDemo\Imagick\functions::load();
     \ImagickDemo\ImagickDraw\functions::load();
     \ImagickDemo\ImagickPixel\functions::load();
     \ImagickDemo\ImagickKernel\functions::load();
     \ImagickDemo\ImagickPixelIterator\functions::load();
     \ImagickDemo\Tutorial\functions::load();
     $resetTimeResourceLimit = false;
     if (false) {
         // ImageMagick has a 'non-optimal' way of measuring time passed
         // https://github.com/ImageMagick/ImageMagick/issues/113
         // Currently it does not appear possible to have both protection
         $maxRunTime = 60;
         // one minute
         $maxRunTime *= 60;
         // 1hour
         // Each image generated hurries up the restart by 50 seconds
         // for a max of 72 images generated per run
         $taskPseudoTime = 50;
         $resetTimeResourceLimit = true;
         // End rant
     } else {
         //Start remove this when time limit can be controlled better
         $maxRunTime = \Imagick::getResourceLimit(\Imagick::RESOURCETYPE_TIME);
         // one minute
         if ($maxRunTime <= 10) {
             $maxRunTime = 45;
         }
         // Each image generated hurries up the restart by 2 seconds
         // for a max of 30 images generated per run
         $taskPseudoTime = 2;
         //End remove this when time limit can be controlled better
     }
     $endTime = time() + $maxRunTime;
     $count = 0;
     while (time() < $endTime) {
         if ($resetTimeResourceLimit === true) {
             \Imagick::setResourceLimit(\Imagick::RESOURCETYPE_TIME, 45);
         }
         $task = $this->taskQueue->waitToAssignTask();
         if (!$task) {
             echo ".";
             $count = $count + 1;
             if ($count % 20 == 0) {
                 echo "\n";
             }
             //Sleep for 1/10th of a second
             usleep(100000);
             continue;
         }
         echo "A task! " . "\n";
         $endTime -= $taskPseudoTime;
         try {
             $startTime = microtime(true);
             $this->execute($task);
             $time = microtime(true) - $startTime;
             $this->asyncStats->recordTime(self::EVENT_IMAGE_GENERATED, $time);
             echo "Task complete\n";
             $this->taskQueue->completeTask($task);
         } catch (\ImagickException $ie) {
             echo "ImagickException running the task: " . $ie->getMessage();
             $this->taskQueue->errorTask($task, get_class($ie) . ": " . $ie->getMessage());
         } catch (\Auryn\BadArgumentException $bae) {
             //Log failed job
             echo "BadArgumentException running the task: " . $bae->getMessage();
             $this->taskQueue->errorTask($task, get_class($bae) . ": " . $bae->getMessage());
         } catch (\Exception $e) {
             echo "Exception running the task: " . $e->getMessage();
             $this->taskQueue->errorTask($task, get_class($e) . ": " . $e->getMessage());
         }
     }
     echo "\nImagickTaskRunner exiting\n";
 }