这是非常基本的,但我有点困惑我哪里出错了(学习如何实现一个 RESTful Web 服务)。上下文是,我有一个简单的simulator.php 文件,它模拟对我的本地PHP 文件之一的HTTP 请求。本地 PHP 文件 (index.php) 只返回一个带有值的变量。所以它几乎是这样的:
<?php
$variable = 'hello';
return $variable;
?>
我的simulator.php 文件有以下内容:
?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost/kixeye/index.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec($ch);
var_dump($contents);
curl_close($ch);
?>
但是,var_dump($contents) 并没有完全吐出从 index.php 返回的 $variable 的值。我不太明白为什么不。