我需要文件流。
例如
private function faviconFoundExec($url)
{
exec('wget ' . $url . ' -O ../favicons/test.jpg 2>&1', $output);
}
将保存实际文件,但我需要文件流,与file_get_contents
将返回的内容相同。
private function faviconFoundGet($url)
{
return @file_get_contents( $url );
}
我正在查看passthru,但文档有点不清楚。
答案 0 :(得分:1)
您可以使用proc_open
从命令中获取流$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
);
$cmd = 'wget -qO- ' . $url;
$process = proc_open($cmd, $descriptorspec, $pipes, realpath('./'), array());
$contents = stream_get_contents($pipes[1]);
fclose($pipes[1]);
// It is important that you close any pipes before calling
// proc_close in order to avoid a deadlock
proc_close($process);