问题
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