CodeIgniter RESTful API rate limiting issue

一世执手 提交于 2019-12-24 02:14:01

问题


I am working with the following code written by Phil Sturgeon here: https://github.com/philsturgeon/codeigniter-restserver

No where in his docs can I see how the limit option is setup in side of the controller.

the RESTController controller file has some references e.g.

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

Shows the protected function, additionally there is:

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

And from the rest.php config:

/* |-------------------------------------------------------------------------- | 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. |

Can anyone help me with this please? Pulling my hair out currently :-)

One of my controllers methods as it currently stands:

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

回答1:


Fixed with:

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



回答2:


Have you tried something like

$this->methods['listservices_get']['limit'] =10 at the top of the function?

If you have a debugger, it might be worth setting a breakpoint in there to check what the limit is set to. and then you can override it before the reponse is called.



来源:https://stackoverflow.com/questions/13252050/codeigniter-restful-api-rate-limiting-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!