cutycapt php,CutyCapt与php exec

博主在CentOS系统中遇到一个问题,即CutyCapt能够通过终端正常工作,但无法通过PHP的exec函数执行。他们尝试了启动Xvfb并在php脚本中使用DISPLAY变量来调用CutyCapt进行网页截图,但没有生成输出文件。在更新中,博主分享了解决方案,通过结合xvfb-run命令和调整参数设置,最终成功在PHP中运行了CutyCapt并生成了截图。
摘要由CSDN通过智能技术生成

我在CentOS上使用CutyCapt.

它通过终端工作正常,但它不能通过

PHP exec功能.

我在终端启动了xvfb命令:

Xvfb :99 -screen 0 1024x768x24

我试图通过php脚本做截图:

exec("DISPLAY=:99 /path/to/cutycapt --url= --out=");

它没有显示任何错误,但没有输出文件(输出目录有chmod 777)

有人能帮助我吗?

谢谢

UPD:

也许以某种方式允许Apache执行Xvfb更好?

最佳答案 我设法让CutyCapt在最后使用php成功运行. $_parameters通过AJAX传递给php脚本.希望这可以帮助…

case 'Output_Chart': {

// We always create the .png. We use the ImageMagick convert (IMC) command to make .pdfs

if ($_Suffix == 'pdf') {

$IMC = ";convert -page 735x850 '$_PathOut/$_ChartName.png' '$_PathOut/$_ChartName.pdf'";

} else {

$IMC = '';

}

// Prepare the query string for the CutyCapt URL

$sQuery_Pattern = '?Path=%s&iDL=%d';

$sQuery = sprintf($sQuery_Pattern, $_Path, $_iDL);

// Prepare CutyCapt's command and parameters (NB: query string and out parameter are enclosed in aposts for the shell)

$sCC_Cmd = '/var/www/LF/Includes/CutyCapt';

$sCC_URL = "http://localhost/LF/LFPrint.html'$sQuery'"; // Note: Inner apostrophes

$sCC_Out = "'$_PathOut/$_ChartName.png'";

$sCC_Pattern = ' --url=%s --out=%s --delay=%d --min-width=%d';

$sCC_Options = sprintf($sCC_Pattern, $sCC_URL, $sCC_Out, $_Delay, $_MinWidth);

//$sCC_CmdLine = $sCC_Cmd . $sCC_Options . " 2> CutyCapt.err.txt";

$sCC_CmdLine = $sCC_Cmd . $sCC_Options . " 2> /dev/null";

// Prepare the final command line with xvfb-run, CutyCapt, and the URL?QueryString

$sCC_CmdLine = 'xvfb-run --auto-servernum --server-args="-screen 0, 800x1000x24" ' . $sCC_CmdLine . $IMC;

exec( $sCC_CmdLine, $aOutput = array(), $ret);

// Wait for and then return the results. sCC_CmdLine and aOutput are just for debugging

echo json_encode(array("ret" => $ret, "cmd" => $sCC_CmdLine, "Output" => $aOutput));

break;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值