CutyCapt与php exec的应用

5

我正在CentOS上使用CutyCapt。它通过终端很好地工作,但是通过php exec函数无法工作。我已经通过终端命令启动了xvfb:

Xvfb :99 -screen 0 1024x768x24

我正在尝试通过PHP脚本进行屏幕截图:

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

这段代码没有显示任何错误,但是没有输出文件(输出目录的chmod为777)。

有人能帮我吗?

谢谢。

更新:也许更好的方法是通过Apache来允许执行Xvfb?


尝试使用以下代码并发布结果。`$output = array(); $return_var = null; $result = exec("DISPLAY=:99 /path/to/cutycapt --url=<some url> --out=<path/to/output>", $output, $return_var);var_dump($result); var_dump($output); var_dump($return_var);` - Babblo
1个回答

3
我已成功运行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;
 }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接