[英]fgets not running on ubuntu 12.04 but fine on windows (local)
我在php中有一個代碼為:
header('Content-Type: text/HTML; charset=utf-8');
header('Content-Encoding: none; ');
$cmd = "pdf2htmlEX --process-outline 0 --fit-width 800 --fit-height 1200 --dest-dir uploaded/uploaded_files uploaded/uploaded_files_21_original/inputfile.pdf 2>&1>>data.log &";
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("pipe", "w") // stderr is a pipe that the child will write to
);
$process = proc_open($cmd, $descriptorspec, $pipes, __DIR__);
//__DIR__ will set CWD
if (is_resource($process)) {
stream_set_blocking($pipes[1], FALSE);
$s = fgets($pipes[1], 1024);
echo $s;
}
這會回聲
預處理0/1
預處理1/1
當我在Windows的Wamp中執行它時。
但是,當我在Ubuntu 12.04 Apache2上運行相同的命令時。 它不回顯任何值。 即,它在回聲中給出空白輸出。
我在這里想念什么? 我缺少一些配置更改嗎? 請幫忙。 謝謝。
首先,您應該啟用錯誤報告 。
// Put these lines to the top of your script
error_reporting(E_ALL);
ini_set('display_errors', true);
ini_set('display_startup_errors', true);
然后使用二進制文件的完整路徑(即使您設置了CWD):
/usr/bin/pdf2htmlEX
如果您不經常從STDERR
讀取數據,則應將其標記為寫追加模式:
2 => array("pipe", "a") // a - append
錯誤也有可能實際上已寫入STDERR
,從中讀取錯誤可能還有消息。
當您在命令2>&1>>data.log &
重定向管道時,我不確定PHP如何處理管道。 嘗試使用和不使用。
我的經驗是popen
效果最好(與所有可用的shell_exec
, system
,...相比),我認為值得嘗試一下popen()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.