how to redirect STDOUT to a file in PHP?

前端 未结 7 1083
不思量自难忘°
不思量自难忘° 2020-11-27 11:56

The code below almost works, but it\'s not what I really meant:

ob_start();
echo \'xxx\';
$contents = ob_get_contents();
ob_end_clean();
file_put_contents($f         


        
7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-27 12:07

    Here is an ugly solution that was useful for a problem I had (need to debug).

    if(file_get_contents("out.txt") != "in progress")
    {
        file_put_contents("out.txt","in progress");
        $content = file_get_contents('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
        file_put_contents("out.txt",$content);
    }
    

    The main drawback of that is that you'd better not to use the $_POST variables. But you dont have to put it in the very beggining.

提交回复
热议问题