【问题标题】:CodeIgniter RESTful API rate limiting issueCodeIgniter RESTful API 速率限制问题
【发布时间】:2012-10-26 11:11:03
【问题描述】:

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

我无法在他的文档中看到控制器一侧的限制选项是如何设置的。

RESTController 控制器文件有一些参考,例如

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

显示受保护的功能,另外还有:

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

从 rest.php 配置:

/* |------------------------------------------------- ------------------------------------- | REST 启用限制 |------------------------------------------------- ------------------------------------- | |当设置为 true 时 REST_Controller 将计算使用次数 每种方法 |每小时通过一个 API 密钥。这是一般规则,可以 在 | 中被覆盖每个控制器中的 $this->method 数组。 |

谁能帮我解决这个问题?目前正在拔头发:-)

目前我的控制器方法之一:

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);
    }
}

【问题讨论】:

  • 有什么问题?你想要没有限制吗?你想为某事设置限制吗?

标签: php api codeigniter


【解决方案1】:

固定为:

    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),
    );

【讨论】:

  • 'level' 索引在做什么?
  • 你是否在 Controller 中覆盖了这个范围?
【解决方案2】:

你有没有尝试过类似的东西

$this->methods['listservices_get']['limit'] =10 在函数顶部?

如果您有调试器,可能值得在其中设置断点以检查设置的限制。然后你可以在调用响应之前覆盖它。

【讨论】:

  • 设法解决了这个问题(下面的答案)希望其他人也能遇到这个问题:-) 感谢 viperfx 的回复
猜你喜欢
  • 1970-01-01
  • 2011-11-16
  • 2015-04-21
  • 1970-01-01
  • 2012-08-24
  • 2014-12-15
  • 1970-01-01
  • 2020-11-04
  • 1970-01-01
相关资源
最近更新 更多