Symfony未捕获异常- '进程已被信号"9"


Symfony Uncaught exception - 'The process has been signaled with signal "9"

当尝试使用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');
    }
}

根据这篇文章,进程已经用信号"9"这可能与您的主机内存不足有关。

i.am。michael Mar 4 at 7:56

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

Dmitry Mar 4 at 11:56

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

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

当您更改您的管理配置时,也可能发生这种情况。

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

在我的情况下,我使用Laravel,我必须设置stopwaitsecs值大于我最长的运行作业(实际上在文档中提到)