【发布时间】:2019-06-02 13:57:13
【问题描述】:
我一直在尝试用 PHP 克隆存储库,为什么输出只显示我
cloning into project-name ?
并且不向我显示下一条消息,例如
远程:枚举对象
远程:计数对象
接收对象 19% (591/3095), 5.06 MiB | 1024.00 KiB/s
这是我执行实时命令的功能
ob_implicit_flush(true);ob_end_flush();
function liveExecuteCommand($cmd)
{
// while (@ ob_end_flush()); // end all output buffers if any
$proc = popen("$cmd 2>&1 ; echo Exit status : $?", 'r');
$live_output = "";
$complete_output = "";
while (!feof($proc))
{
$live_output = fread($proc, 4096);
$complete_output = $complete_output . $live_output;
echo "$live_output";
// @ flush();
}
pclose($proc);
// get exit status
preg_match('/[0-9]+$/', $complete_output, $matches);
// return exit status and intended output
return array (
'exit_status' => intval($matches[0]),
'output' => str_replace("Exit status : " . $matches[0], '', $complete_output)
);
}
然后我调用函数:
liveExecuteCommand('git clone https://username:password@gitlab.com/example/project.git');
谁能帮帮我?
【问题讨论】:
标签: php linux git console exec