【问题标题】:Symfony Uncaught exception - 'The process has been signaled with signal "9"Symfony 未捕获异常 - '进程已收到信号“9”的信号
【发布时间】:2016-01-13 19:31:26
【问题描述】:

尝试使用 Phantomjs 和 Symfony 的 Process 和 Reposonse 文件创建 PDF 文档时出现此错误。

这是我收到的错误消息

致命错误:未捕获的异常 'Symfony\Component\Process\Exception\RuntimeException' 带有消息“进程已收到信号“9”的信号。'

下面是我的代码:控制器文件

    namespace PhantomFox\Capture;

    use PhantomFox\Views\View;
    use Symfony\Component\Process\Process;
    use Symfony\Component\HttpFoundation\Response;

    class Capture
    {   
        protected $view;
        protected $pdf;

        public function __construct()
        {
            $this->view = new View;
        }

        public function load($filename, array $data = [])
        {
            $view = $this->view->load($filename, $data);

            $this->pdf = $this->captureImage($view);
        }

        public function respond($filename)
        {
            $response = new Response(file_get_contents($this->pdf), 200, [
                'Content-Description' => 'File Transfer',
                'Content-Disposition' => 'attachment; filename="' . $filename . '"',
                'Content-Transfer-Encoding' => 'binary',
                'Content-Type' => 'application/pdf',
            ]);

            unlink($this->pdf);

            $response->send();
        }

        protected function captureImage($view)
        {
            $path = $this->writeFile($view);

            $this->phantomProcess($path)->setTimeout(10)->mustRun();

            return $path;
        }
    protected function writeFile($view)
    {
        file_put_contents($path = 'app/tmp/storage/' . md5(uniqid()) . '.pdf' , $view);

        return $path;
    }

    public function phantomProcess($path)
    {
        return new Process('app/bin/phantomjs capture.js ' . $path);
    }

}

这是我的视图文件:

class AppController extends Controller {

    public function index() {

        $this->capture->load('index.html', [
            'order' => '123456',
            'name' => 'Wes Murray',
            'amount' => 100.00,
        ]);

        $this->capture->respond('index.pdf');

    }
}

【问题讨论】:

  • 我在尝试使用 FFmpeg 将 4k 视频编码为不同分辨率时遇到了同样的异常

标签: php symfony pdf twig


【解决方案1】:

根据这篇帖子The process has been signaled with signal "9",这可能与您的主机内存不足有关。

i.am.michiel 3 月 4 日 7:56

这实际上可能是资源问题。你可能想检查 服务器的虚拟硬件。

德米特里 3 月 4 日 11:56

@i.am.michiel,谢谢,虚拟服务器内存不足。

检查您的服务器设置和硬件是否适合您要运行的 PDF 操作。

【讨论】:

  • 我没有使用虚拟服务器,我在 Mac OSX 上运行 Apache 堆栈,硬件:Core i5 - 8GB 内存和 500GB 硬盘。我调整了内存限制,但没有运气
  • 我遇到了类似的问题,更改了分配给我的 VM 的 RAM 数量,然后它就可以工作了。那么这是一个内存问题。我从 2048 增加到 8192 MB
【解决方案2】:

这也可能在您更改 supervisord 配置时发生。

当您更改配置并运行 reread 和 update 命令时,supervisord 将向子进程发送停止信号。如果它们没有在 stopwaitsecs 配置变量指定的时间内完成,它们会被 9 个信号杀死。

就我而言,我使用的是 Laravel,我必须将 stopwaitsecs 值设置为大于我运行时间最长的作业(正如文档中实际提到的那样)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多