当尝试使用 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);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的视图文件:
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');
}
}
Run Code Online (Sandbox Code Playgroud)
根据这篇文章,该进程已收到信号“9”的信号,这可能与您的主机内存不足有关。
i.am.michiel 3 月 4 日 7:56
这实际上可能是一个资源问题。您可能想检查服务器的虚拟硬件。
德米特里 3 月 4 日 11:56
@i.am.michiel,谢谢,虚拟服务器刚刚内存不足。
检查您的服务器设置和硬件是否适合您要运行的 PDF 操作类型。
| 归档时间: |
|
| 查看次数: |
18744 次 |
| 最近记录: |