简体   繁体   中英

PHP Image processing queue, problems with finished jobs

I'm working on image processing with PHP, the steps are:

  1. A user uploads several images.
  2. ImageMagick / GraphicsMagick make 4 copies in different sizes
  3. These copies are processed by jpegtran
  4. Once processed are uploaded to Amazon S3

My problem:

  • How I can know when finished imagemagick to start jpegtran?
  • How I can know when finsihed jpegtran to start uploading to S3?

I'm using Gearman, is it correct to have a worker for imagemagick, another worker for jpegtran and another worker to S3?

Thanks for the help

Your worker could start the next process.

class ImagemagickWorker
{
    public function imagemagicProcessing (GearmanJob $job)
    {
        // your image processing code
        $gmClient = new GearmanClient();
        $gmClient->do('jpegtranProcessing', $workload);
    }
}

Case you need more complex control over processing consider using tasks and defining callbacks.

class ImagemagickTask
{
    public function imagemagicProcessing ($workload)
    {
        // do whatever you need to do
        $gmClient = new GearmanClient();
        $gmClient->setCompleteCallback (
            function (GearmanTask $task) use ($gmClient)
            {
                 // repeat the process
            }
        );
        $gmClient->addTask('imagemagicProcessing', $workload);
        $gmClient->runTasks();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM