【问题标题】:Log to file output of an exec() command triggered from php记录到从 php 触发的 exec() 命令的文件输出
【发布时间】:2014-10-06 11:00:39
【问题描述】:

我有一个使用 imagick 将 PDF 文件转换为图像的 php 脚本。

它在我的本地机器上工作,但在生产服务器中它无法执行命令,但不确定原因,因为我看不到我的命令执行输出。

没有 SSH 访问权限或管理面板。

为了解决这个问题,我需要知道如何将我的 php 脚本在 shell 中执行此命令的输出记录到文本文件中,以便在失败后通过 ftp 下载并阅读它。

exec('convert -density 150 -quality 100 -sharpen 0x2.0 -background white -alpha remove ' . $file->getFileInfo()->getRealPath() . ' ' . $save_to, $result, $error);

$result 变量我尝试使用print_r($result);,它只显示Array ()

【问题讨论】:

    标签: php logging error-handling exec imagick


    【解决方案1】:

    您可以使用与exec() 相同的shell_exec(),并通过这种方式为您输出结果以检查错误在哪里。

    $error = shell_exec('convert -density 150 -quality 100 -sharpen 0x2.0 -background white -alpha remove ' . $file->getFileInfo()->getRealPath() . ' ' . $save_to . ' 2>&1');
    
    print_r($error);
    
    exit;
    

    【讨论】:

    • 这可以解决问题,现在我知道问题是服务器上的 ImageMagick 非常旧,而且我在命令中使用的 -alpha 选项缺少这个。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-03
    相关资源
    最近更新 更多