しばらくしてPHPもしくはshell_exec戻り、空の文字列

証券ブレイク:

私が使用してsymfonyのコンソールコマンド作らpngquantプロセスへとイメージの長いリストを圧縮します。イメージは、CSVファイルから読み込まれます。

バッチがされてローカル環境で最後まで正常に動作しますが、ステージの環境では、約5分間動作しますし、それから空の結果を返す開始しますshell_execコマンド。私も再試行システムを作ったが、それは常に空の結果を返します:

// escapeshellarg() makes this safe to use with any path
// errors are redirected to standard output
$command = sprintf(
    '%s --quality %d-%d --output %s --force %s 2>&1',
    $this->pngquantBinary,
    $minQuality,
    $maxQuality,
    escapeshellarg($tempPath),
    $path
);

// tries a few times
$data    = null;
$attempt = 0;

do {
    // command result
    $data = shell_exec($command);

    // error
    if (null !== $data) {
        $this->logger->warning('An error occurred while compressing the image with pngquant', [
            'command' => $command,
            'output'  => $data,
            'cpu'     => sys_getloadavg(),
            'attempt' => $attempt + 1,
            'sleep'   => self::SLEEP_BETWEEN_ATTEMPTS,
        ]);
        sleep(self::SLEEP_BETWEEN_ATTEMPTS);
    }

    ++$attempt;
} while ($attempt < self::MAX_NUMBER_OF_ATTEMPTS && null !== $data);

// verifies that the command has finished successfully
if (null !== $data) {
    throw new \Exception(sprintf('There was an error compressing the file with command "%s": %s.', $command, $data));
}

問題があるということと同じ環境で、別のシェルで実行同じコマンドが正常に動作します私は、同じサーバー上の別のインスタンスでまったく同じコマンドを入れた場合、私は、エラーを記録する際、意味、罰金に動作します。

でも、symfonyのから私はより詳細なエラーを探してくださいすべてのエラーを読み取ることができない記録しますか?

この原因は何をすることができますか?メモリとプロセッサは、実行時に細かいです!

証券ブレイク:

多くの試みの後、私はこの質問をお読みください。

Symfony2のプロセスコンポーネント - パイプを作成し、新しいプロセスを起動することができません

ソリューションは、呼び出しを追加したgc_collect_cyclesループの中にフラッシュした後!

if ($flush || 0 === ($index % self::BATCH_SIZE)) {
    $this->em->flush();
    $this->em->clear();

    // clears the temp directory after flushing
    foreach ($this->tempImages as $tempImage) {
        unlink($tempImage);
    }
    $this->tempImages = [];

    // forces collection of any existing garbage cycles
    gc_collect_cycles();
}

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=26336&siteId=1