Symfony 未捕获异常 - '进程已收到信号“9”
Symfony Uncaught exception - 'The process has been signaled with signal "9"
我在尝试使用 Phantomjs 和 Symfony 的 Process 和 Reposonse 文件创建 PDF 文档时遇到此错误。
这是我收到的错误信息
致命错误:未捕获异常 'Symfony\Component\Process\Exception\RuntimeException' 消息 'The process has been signaled with signal "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');
}
}
根据此 post The process has been signaled with signal "9" 这可能与您的主机 运行 内存不足有关。
i.am.michiel 3 月 4 日在 7:56
This might actually be a ressources problem. You might want to check
your server's virtual hardware.
Dmitry 3 月 4 日在 11:56
@i.am.michiel , Thanks, virtual server just ran out of memory.
检查您的服务器设置和硬件是否适合您想要的 PDF 操作类型运行。
当您更改 supervisord 配置时也会发生这种情况。
当您更改配置并运行重新读取和更新命令时,supervisord 将向子进程发送停止信号。如果它们没有在 stopwaitsecs 配置变量指定的时间内完成,它们将被 9 个信号杀死。
在我的例子中,我使用的是 Laravel 并且我必须将 stopwaitsecs 值设置为大于我最长的 运行ning 作业(正如文档中实际提到的那样)
我在尝试使用 Phantomjs 和 Symfony 的 Process 和 Reposonse 文件创建 PDF 文档时遇到此错误。
这是我收到的错误信息
致命错误:未捕获异常 'Symfony\Component\Process\Exception\RuntimeException' 消息 'The process has been signaled with signal "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');
}
}
根据此 post The process has been signaled with signal "9" 这可能与您的主机 运行 内存不足有关。
i.am.michiel 3 月 4 日在 7:56
This might actually be a ressources problem. You might want to check your server's virtual hardware.
Dmitry 3 月 4 日在 11:56
@i.am.michiel , Thanks, virtual server just ran out of memory.
检查您的服务器设置和硬件是否适合您想要的 PDF 操作类型运行。
当您更改 supervisord 配置时也会发生这种情况。
当您更改配置并运行重新读取和更新命令时,supervisord 将向子进程发送停止信号。如果它们没有在 stopwaitsecs 配置变量指定的时间内完成,它们将被 9 个信号杀死。
在我的例子中,我使用的是 Laravel 并且我必须将 stopwaitsecs 值设置为大于我最长的 运行ning 作业(正如文档中实际提到的那样)