php - CodeIgniter RESTful API 速率限制问题

标签 php api codeigniter

我正在使用 Phil Sturgeon 编写的以下代码:https://github.com/philsturgeon/codeigniter-restserver

在他的文档中,我没有看到如何在 Controller 一侧设置限制选项。

RESTController Controller 文件有一些引用,例如

第 654 行:https://github.com/philsturgeon/codeigniter-restserver/blob/master/application/libraries/REST_Controller.php

显示 protected 函数,另外还有:

 // How many times can you get to this method an hour?
 $limit = $this->methods[$controller_method]['limit'];

从rest.php配置中:

/* |-------------------------------------------------------------------------- | REST Enable Limits |-------------------------------------------------------------------------- | | When set to true REST_Controller will count the number of uses of each method | by an API key each hour. This is a general rule that can be overridden in the | $this->method array in each controller. |

有人可以帮我解决这个问题吗?目前正在拔我的头发:-)

我目前的 Controller 方法之一:

function listservices_get()
{
    $organisation_id = $this->get('id');
    $organisations = $this->api_buyus_model->list_services($organisation_id);

    if($organisations)
    {
            $this->response($organisations, 200);
    }
    else
    {
            $this->response(array('error' => '1', 'errorDesc' => 'Buy us services list could not be retrieved.'), 400);
    }
}

最佳答案

修复:

    protected $methods = array(
            'index_put' => array('level' => 10, 'limit' => 10),
            'index_delete' => array('level' => 10),
            'level_post' => array('level' => 10),
            'regenerate_post' => array('level' => 10),
    );

关于php - CodeIgniter RESTful API 速率限制问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13252050/

相关文章:

php - 如何在 HTML/Javascript 中像 Windows 帮助中那样做树结构

javascript - 如何通过上传图片检查按钮点击的 session

mysql - Bootstrap 2.3 中的预输入

php - 无法从 ReCaptchaResponse 获取错误代码

php - 将 JSON 对象附加到 URL 末尾

php - 在 Laravel 5.5 中收到错误的重置密码链接

api - 如何使用任何 API 检查 Symfony 的最新可用版本?

python - 预先验证 API 测试请求 URL 列表

amazon-web-services - 如何为 Route53 -> EC2 -> API 端点反向代理路径设置 HTTP 测试

php - 使用 Codeigniter 从 MySql 返回的 Fullcalendar.js allDay 参数