在具有返回值的php中调用php脚本

use*_*775 2 php curl

我试图从脚本中获取返回值,该脚本按回显返回“完成”或“错误”。首先,我可以使用php函数file_get_contents,但它会返回我的整个脚本,而不仅是我要在脚本中打印的内容。然后我相信了这种cURL方法,但是它无法正常工作。

该脚本称为:

<?php 
include("config.php");
print "complete";
?>
Run Code Online (Sandbox Code Playgroud)

我卷曲的脚本:

$url="caller.php";
$ch = curl_init(); //initialize curl handle
curl_setopt($ch, CURLOPT_URL, $url); //set the url
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); //return as a variable
$response = curl_exec($ch); //run the whole process and return the response
curl_close($ch); //close the curl handle

echo "test". $response."|";
Run Code Online (Sandbox Code Playgroud)

为什么这不起作用?而我该如何运作呢?FILE方法?

jer*_*oen 5

如果要捕获所包含脚本的回显值,则可以使用输出缓冲:

<?php
ob_start();    // start output buffering
include("caller.php");
$returned_value = ob_get_contents();    // get contents from the buffer
ob_end_clean();    // stop output buffering
?>
Run Code Online (Sandbox Code Playgroud)