execInBackground() public static method

public static execInBackground ( string $cmd, null | string $outputFile = null ) : integer
$cmd string
$outputFile null | string
return integer
Beispiel #1
0
 /**
  * @param $documentId
  * @param $config
  * @throws \Exception
  */
 public function preparePdfGeneration($documentId, $config)
 {
     $document = $this->getPrintDocument($documentId);
     if (Model\Tool\TmpStore::get($document->getLockKey())) {
         throw new \Exception("Process with given document alredy running.");
     }
     Model\Tool\TmpStore::add($document->getLockKey(), true);
     $jobConfig = new \stdClass();
     $jobConfig->documentId = $documentId;
     $jobConfig->config = $config;
     $this->saveJobConfigObjectFile($jobConfig);
     $this->updateStatus($documentId, 0, "prepare_pdf_generation");
     $args = ["-p " . $jobConfig->documentId];
     $env = \Pimcore\Config::getEnvironment();
     if ($env !== false) {
         $args[] = "--environment=" . $env;
     }
     $cmd = Tool\Console::getPhpCli() . " " . realpath(PIMCORE_PATH . DIRECTORY_SEPARATOR . "cli" . DIRECTORY_SEPARATOR . "console.php") . " web2print:pdf-creation " . implode(" ", $args);
     Logger::info($cmd);
     if (!$config['disableBackgroundExecution']) {
         Tool\Console::execInBackground($cmd, PIMCORE_LOG_DIRECTORY . DIRECTORY_SEPARATOR . "web2print-output.log");
     } else {
         Processor::getInstance()->startPdfGeneration($jobConfig->documentId);
     }
 }
 /**
  * @param $package
  * @return string
  * @throws \Exception
  */
 public static function installPackage($package)
 {
     $logFile = self::getLogFile();
     $jobId = uniqid();
     $pidFile = self::getPidFile($jobId);
     $console = implode(DIRECTORY_SEPARATOR, [PIMCORE_PATH, 'cli', 'console.php']);
     $cmd = implode(' ', [Console::getPhpCli(), $console, 'manager:require', '-p ' . $pidFile, '-r ' . $package]);
     if (is_file($logFile)) {
         unlink($logFile);
     }
     file_put_contents($pidFile, $jobId);
     Console::execInBackground($cmd, $logFile);
     return $jobId;
 }
 /**
  * @return mixed|void
  * @throws \Exception
  */
 public function save()
 {
     if ($this->getDestinationFile()) {
         if (is_file($this->getConversionLogFile())) {
             $this->deleteConversionLogFile();
         }
         if (is_file($this->getDestinationFile())) {
             @unlink($this->getDestinationFile());
         }
         // get the argument string from the configurations
         $arguments = implode(" ", $this->arguments);
         // add format specific arguments
         /*if($this->getFormat() == "f4v") {
               $arguments = "-f flv -vcodec libx264 -acodec libfaac -ar 44000 -g 100 " . $arguments;
           } else*/
         if ($this->getFormat() == "mp4") {
             // `-coder 0 -bf 0 -flags2 -wpred-dct8x8 -wpredp 0´ is the same as to -vpre baseline, using this to avid problems with missing preset files
             // Some flags used were deprecated already
             // todo set the -x264opts flag correctly and get profiles working as they should.
             $arguments = "-strict experimental -f mp4 -vcodec libx264 -acodec aac -g 100 -pix_fmt yuv420p -movflags faststart " . $arguments;
         } else {
             if ($this->getFormat() == "webm") {
                 // check for vp9 support
                 $webmCodec = "libvpx";
                 $codecs = Console::exec(self::getFfmpegCli() . " -codecs");
                 if (stripos($codecs, "vp9")) {
                     //$webmCodec = "libvpx-vp9"; // disabled until better support in ffmpeg and browsers
                 }
                 $arguments = "-strict experimental -f webm -vcodec " . $webmCodec . " -acodec libvorbis -ar 44000 -g 100 " . $arguments;
             } else {
                 throw new \Exception("Unsupported video output format: " . $this->getFormat());
             }
         }
         // add some global arguments
         $arguments = "-threads 0 " . $arguments;
         $cmd = self::getFfmpegCli() . ' -i ' . realpath($this->file) . ' ' . $arguments . " " . str_replace("/", DIRECTORY_SEPARATOR, $this->getDestinationFile());
         Console::execInBackground($cmd, $this->getConversionLogFile());
     } else {
         throw new \Exception("There is no destination file for video converter");
     }
 }
 public function sendAction()
 {
     $letter = Newsletter\Config::getByName($this->getParam("name"));
     if ($letter) {
         $cmd = Tool\Console::getPhpCli() . " " . realpath(PIMCORE_PATH . DIRECTORY_SEPARATOR . "cli" . DIRECTORY_SEPARATOR . "console.php") . " internal:newsletter-send " . escapeshellarg($letter->getName()) . " " . escapeshellarg(Tool::getHostUrl());
         Tool\Console::execInBackground($cmd, PIMCORE_LOG_DIRECTORY . "/newsletter--" . $letter->getName() . ".log");
     }
     $this->_helper->json(array("success" => true));
 }
Beispiel #5
0
 /**
  *
  */
 public function convert()
 {
     $this->save();
     $cmd = Console::getPhpCli() . " " . realpath(PIMCORE_PATH . DIRECTORY_SEPARATOR . "cli" . DIRECTORY_SEPARATOR . "console.php") . " internal:video-converter " . $this->getProcessId();
     Console::execInBackground($cmd);
 }
Beispiel #6
0
 /**
  * @param $script
  * @param $arguments
  * @param $outputFile
  * @return string
  */
 public static function runPhpScriptInBackground($script, $arguments = "", $outputFile = null)
 {
     $cmd = self::buildPhpScriptCmd($script, $arguments);
     $return = Console::execInBackground($cmd, $outputFile);
     return $return;
 }