0

I need to include the output/result of a PHP file in another file.

I found info online about using curl to do this, but it doesn't seem to work so well, and so efficiently.

This is my current code:

function curl_load($url){
    curl_setopt($ch=curl_init(), CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $response = curl_exec($ch);
    curl_close($ch);
    return $response;
}

$url = "http://domain.com/file.php";
$output = curl_load($url);

echo "output={$output}";

Any recommendations on what I can use to make this more efficient/work better?

I'm looking for whichever method would be the fastest and most efficient, since I have a bunch of connections/users that will be using this file constantly to get updated information.

Thanks!

4

2 回答 2

3

file_get_contents() 可能适合您

$homepage = file_get_contents('http://www.example.com/');
echo $homepage;

您还可以使用 file() 或 fopen()

$homepage = file('http://www.example.com/');

$homepage = fopen("http://www.example.com/", "r");
于 2013-11-05T08:26:51.983 回答
0

我最终使用了一个 PHP 包含语句来包含另一个文件。我忘了提到该文件是本地的,这似乎在这一点上最有意义 - 而不是在另一个 PHP 文件中回显结果,我只是将结果设置为一个变量,然后拉那个变量在我的另一个文件中。

于 2013-11-13T09:09:35.420 回答