php - Codeigniter REST API 耗时

标签 php codeigniter rest time response

我正在使用 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/

相关文章:

php - 使用数据库内容预加载 CKEditor 时遇到问题

java - Rest Web 服务 JSON 请求正文,其中 "truee"作为 boolean 真值

spring - 放置在Docker中时Spring应用程序无法通信

php - 对数据库中的结果进行排序,从数字 1 开始

PHPMailer 发送邮件但没有文件附件

php - MYSQL PHP PDO如何获取1条记录

mysql - 如何组合 2 个 SQL 查询以获得 1 个结果

php - 错误 : Unknown column 'Array' in 'field list' (codeigniter)

php - javascript函数保存到cookie

api - API 是否应该将所有工作委托(delegate)给其他服务?