我正在使用 codeigniter REST-API(作者:philsturgeon 引用 URL:
https://github.com/philsturgeon/codeigniter-restserver )
我想将服务生成和处理响应所花费的时间添加到响应中。
我正在尝试在我的 Controller 中使用 $this->benchmark->elapsed_time()
,但它不发送时间而是发送
"success": 1,"took": "{elapsed_time}",
我尝试编辑 api abstract class REST_Controller extends CI_Controller
的主 Controller ,并将耗时附加到 public function response($data = null, $ http_code = null, $continue = false)
但运气不好,我一直收到 "{elapsed_time}"
非常感谢任何帮助。
最佳答案
你可以使用这个获取你的elapsed_time
$this->benchmark->mark('code_start');
// Some code happens here
$this->benchmark->mark('code_end');
echo $this->benchmark->elapsed_time('code_start', 'code_end');
关于php - Codeigniter REST API 耗时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31177969/