CodeIgniter RESTful API 速率限制问题 [英] CodeIgniter RESTful API rate limiting issue

查看:30
本文介绍了CodeIgniter RESTful API 速率限制问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

the RESTController controller file has some references e.g.

第 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'];

从 rest.php 配置:

And from the rest.php config:

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

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

推荐答案

已修复:

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

这篇关于CodeIgniter RESTful API 速率限制问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆