我需要将对 API 的访问限制为每秒 10 个请求。
这是我根据他们的文档使用的区域:
limit_req_zone $binary_remote_addr zone=mylimit:10m 速率=10r/s;
该区域以用户IP地址为标识,对使用限制进行评级。人们通常使用相同的 IP 地址来访问我们的系统。
我想知道是否可以使用用户 tokenId 作为速率限制的标识。我们所有的请求都tokenID在 URL 中包含一个参数:www.example.com/api/events/?tokenID=*****。
有什么线索吗?
谢谢。
更新
我尝试创建区域:
limit_req_zone "$tokenid" zone=limit:10m rate=1r/s;(1 r/s 用于测试)并提取变量,$tokenid如下所示:
limit_req_zone "$tokenid" zone=limit:10m rate=1r/s;
server {
...
location ~ \.php {
...
if ($args ~* "tokenID=([^&]+)") {
set $tokenid "$1";
}
...
}
}
Run Code Online (Sandbox Code Playgroud)
该变量$tokenid确实包含确切的令牌(已测试向响应添加标头),但它似乎没有更新limit_req_zone.
我如何在 C 中做一些像(在 PHP 中)这段代码一样简单的事情:
char buffer[5] = "testing";
FILE* file2 = fopen("data2.bin", "wb");
fwrite(buffer, sizeof buffer, 1, file2);
fclose(file2);
Run Code Online (Sandbox Code Playgroud)
每当我尝试用 PHP 编写二进制文件时,它都不是真正的二进制文件。
例子:
$ptr = fopen("data2.bin", 'wb');
fwrite($ptr, "testing");
fclose($ptr);
Run Code Online (Sandbox Code Playgroud)
我在互联网上发现我需要使用它pack()来执行此操作...
我的期望:
testing\9C\00\00
or
7465 7374 696e 679c 0100 00
Run Code Online (Sandbox Code Playgroud)
我得到了什么:
testing412
Run Code Online (Sandbox Code Playgroud)
谢谢
我删除了本地分支中的一些内容(包括目录和文件).
当我承诺时,它说:
mauricio@mauricio-ubuntu:/var/www/moke$ git commit -m "Better implementation"
[ajax_branch 1a407ad] Better implementation
56 files changed, 23465 insertions(+), 8 deletions(-)
Run Code Online (Sandbox Code Playgroud)
然后我推:
mauricio@mauricio-ubuntu:/var/www/moke$ git push origin ajax_branch
Counting objects: 25, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (18/18), done.
Writing objects: 100% (18/18), 7.97 KiB, done.
Total 18 (delta 6), reused 0 (delta 0)
To git@github.com:giordanoapps/moke.git
17f53bb..1a407ad ajax_branch -> ajax_branch
Run Code Online (Sandbox Code Playgroud)
但是我在本地分支中删除的文件保存在远程分支中.
我究竟做错了什么?
我有以下数组:
$arr = [
"elem-1" => [ "title" => "1", "desc" = > "" ],
"elem-2" => [ "title" => "2", "desc" = > "" ],
"elem-3" => [ "title" => "3", "desc" = > "" ],
"elem-4" => [ "title" => "4", "desc" = > "" ],
]
Run Code Online (Sandbox Code Playgroud)
首先,我需要将值更改[ "title" => "1", "desc" = > "" ]为1(标题值).
我这样做使用array_walk:
array_walk($arr, function(&$value, $key) {
$value = $value["title"];
});
Run Code Online (Sandbox Code Playgroud)
这将正确替换我的价值.我们现在的阵列现在是:
$arr = [
"elem-1" => "1", …Run Code Online (Sandbox Code Playgroud) 我是iOS的新手,我正在学习本教程.
这是我尝试将IBAction连接到我的视图的屏幕截图.
我想在releaseKeyboard每次触摸视图时执行该方法(即关闭键盘).
我没有使用故事板.

我的文件:
challAppDelegate.h
#import <UIKit/UIKit.h>
@interface challAppDelegate : UIResponder <UIApplicationDelegate>
{
UINavigationController *navigationController;
}
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UINavigationController *navigationController;
@end
Run Code Online (Sandbox Code Playgroud)
challAppDelegate.m
#import "challAppDelegate.h"
#import "challViewController.h"
@implementation challAppDelegate
@synthesize window = _window;
@synthesize navigationController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIViewController *rootController =
[[challViewController alloc]
initWithNibName:@"challViewController" bundle:nil];
navigationController = [[UINavigationController alloc]
initWithRootViewController:rootController];
self.window = [[UIWindow alloc]
initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return …Run Code Online (Sandbox Code Playgroud)