【发布时间】: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 视频编码为不同分辨率时遇到了同样的异常