MySql与Laravel Queue,Supervisor和FFMPEg一起停止运行

时间:2014-06-13 14:50:54

标签: php mysql linux laravel-4 ffmpeg

设置队列侦听器以使用FFMPEG处理上传的视频后,我多次回到服务器,发现MySql已停止运行。我检查了驱动器空间,它使用了大约77%(60G中的43G)。

这是我的代码,以防它有用:

public function fire($job, $data)
{
$data = json_decode($data['transcoding_message'], true);
$output_directory = '/home/ubuntu/transcodes/';
$amazon_array = array();

$s3 = AWS::get('s3');


    //execute main transcoding thread

    $cmd = 'sudo ffmpeg -i ' . $data['temp_file_url'] . ' -y -vcodec libx264 -tune zerolatency -movflags faststart -crf 20 -profile:v main -level:v 3.1 -acodec libfdk_aac -b:a 256k ' . $output_directory. $data['temp_file_key'] . '_HQ.mp4 -vcodec libx264 -s ' . $sq_width . 'x' . $sq_height . ' -tune zerolatency -movflags faststart -crf 25 -profile:v main -level:v 3.1 -acodec libfdk_aac -b:a 256k ' . $output_directory. $data['temp_file_key'] . '_SQ.mp4 -ss ' . $seek_half . ' -f image2 -vf scale=iw/2:-1 -vframes 1 ' . $output_directory. $data['temp_file_key'] . '_thumb.jpg';

    exec($cmd." 2>&1", $out, $ret);


    if ($ret)
    {

        Log::error($cmd);
        echo 'Processing error' . PHP_EOL;
        //there was a problem
        return;
    }

    else
    {
        //setup file urls
    echo 'about to move files';

    $hq_url = $this->bucket_root . $data['user_id'] . '/' . $data['temp_file_key'] . '_HQ.mp4';
    $sq_url = $this->bucket_root . $data['user_id'] . '/' . $data['temp_file_key'] . '_SQ.mp4';;
    $thumb_url = $this->bucket_root . $data['user_id'] . '/' . $data['temp_file_key'] . '_thumb.jpg';

    $amazon_array['video_hq_url'] = $data['temp_file_key'] . '_HQ.mp4';
    $amazon_array['video_sq_url'] = $data['temp_file_key'] . '_SQ.mp4';
    $amazon_array['video_thumb_url'] = $data['temp_file_key'] . '_thumb.jpg';

            //copy from temp to permanent

    foreach ($amazon_array as $k => $f)
    {
        $uploader = UploadBuilder::newInstance()
            ->setClient($s3)
            ->setSource($output_directory.$f)
            ->setBucket($this->bucket)
            ->setKey('users/' . $data['user_id'] . '/' . $f)
            ->setConcurrency(10)
            ->setOption('ACL', 'public-read')
            ->build();

        $uploader->getEventDispatcher()->addListener(
            'multipart_upload.after_part_upload',
            function($event) use ($f) {
                // Do whatever you want
            }
        );

        try {
            $uploader->upload();
            echo "{$k} => Upload complete.\n" . PHP_EOL;

            DB::table('items')->where('id', $data['item_id'])->update(array($k => $this->bucket_root. $data['user_id'] . '/' .$f, 'deleted_at' => NULL));
            //delete local

            unlink($output_directory.$f);

            unset($uploader);
        } catch (MultipartUploadException $e) {
            $uploader->abort();
            echo "{$k} => Upload failed.\n" . PHP_EOL;
            continue;
        }
    }

        //write to database

            DB::table('archives_items')->where('id', $data['archive_item_id'])->update(array('deleted_at' => NULL));
            DB::connection('mysql3')->table('video_processing')->where('id', $data['id'])->update(array('finished_processing' => 1));

        //delete files

        //delete s3
        $s3->deleteObject(
            array(
                'Bucket' => $this->temp_bucket,
                'Key' => $data['file_name']
            )
        );
        echo $data['temp_file_url'] . '=>' . " deleted from temp bucket.\n" . PHP_EOL;
        DB::connection('mysql3')->table('video_processing')->where('id', $data['id'])->update(array('deleted_at' => \Carbon\Carbon::now()));

    }
        $job->delete();

        // end of processing uploaded video
        }


    else
    {
        return;
    }

关于为什么MySql会像那样死的任何想法?

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)

编辑:我想补充一点,php artisan队列:listen命令是通过Supervisor触发的,我有4个正在运行的并发进程。

0 个答案:

没有答案