从PHP执行Puppeteer时出错 [英] Error executing Puppeteer from PHP

查看:289
本文介绍了从PHP执行Puppeteer时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个节点脚本,可以将网页转换为PDF文档.用户输入一些内容,然后PHP构建一个HTML页面,然后将其用于节点脚本(运行Puppeteer,使用示例脚本)将其转换为PDF.

I have a node script which converts a webpage into a PDF document. The user enters some content and PHP builds a HTML page, which then is used in a node script (that runs Puppeteer, using a slightly modified version of an example script) to convert it to PDF.

但是当我在PHP中 exec 时,该命令将运行节点脚本,它失败并显示以下错误:

But when I exec in PHP the command to run the node script, it fails with the following error:

(node:14832) UnhandledPromiseRejectionWarning: Error: Failed to launch chrome!
[0424/165455.239499:ERROR:icu_util.cc(133)] Invalid file descriptor to ICU data received.
[0424/165455.239717:FATAL:content_main_delegate.cc(53)] Check failed: false.
#0 0x55f27f255b0c base::debug::StackTrace::StackTrace()
#1 0x55f27f26e780 logging::LogMessage::~LogMessage()
#2 0x55f27d5f7d23 content::ContentMainDelegate::TerminateForFatalInitializationError()
#3 0x55f27ef90deb content::ContentMainRunnerImpl::Initialize()
#4 0x55f27ef9ab72 service_manager::Main()
#5 0x55f27ef8ff14 content::ContentMain()
#6 0x55f28309f9b9 headless::(anonymous namespace)::RunContentMain()
#7 0x55f28309fa42 headless::HeadlessBrowserMain()
#8 0x55f27ef97f9d headless::HeadlessShellMain()
#9 0x55f27d5f61ac ChromeMain
#10 0x7efcaad45c05 __libc_start_main
#11 0x55f27d5f602a _start

PHP正在使用apache用户运行.但是,如果我与用户一起运行相同的脚本,则可以完美运行.当我在终端中使用su - apache -c 'node ...'执行时,它再次引发上述错误.

PHP is running with the apache user. However, if I run the same script with my user, it works perfectly. When I execute in a terminal using su - apache -c 'node ...' it again throws the error described above.

是什么原因导致错误?与apache用户的权限有关吗?我已经遵循了所有麻烦提示指南,但此刻我还没有运气.

What is causing the error? Something related to apache user's permissions? I've followed all troubleshotting guides but I had no luck at the moment.

推荐答案

该问题似乎来自于操纵up使用的默认铬的文件系统权限:

The problem seems to come from the file-system permissions on the default chromium used by puppeteer:

使用ACL(我的nginx组是www-data,请根据您的要求更改Apache):

using ACL( my nginx group is www-data, change with yours for apache):

sudo setfacl -R -m g:www-data:rX node_modules/puppeteer/.local-chromium/

sudo setfacl -dR -m g:www-data:rX node_modules/puppeteer/.local-chromium/

设置权限后,错误消失了.

after setting the permissions the error went away.

这篇关于从PHP执行Puppeteer时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆