Skip to content
KitploitKITPLOIT
أدواتالمدونة
إرسال
أدواتالمدونة
إرسال

أدوات الاختراق واختبار الاختراق والأمن السيبراني لترسانتك الأمنية!

Kitploit هو دليل لأدوات الاختراق والأمن السيبراني واختبار الاختراق. اكتشف آخر تحديثات المشاريع للعثور على الثغرات وتحليل الأنظمة وأتمتة الاختبارات وتعزيز أمنك.

··الخلاصات·اتصال·الخصوصية·© 2026 Kitploit

دليل الأدوات

الفئات

عرض جميع الفئات
Loading categories
limitrr-php — تحديد معدل أفضل لطلبات PHP باستخدام Redis. | Kitploit
أدوات/GitHubGitHub/eddiejibson/limitrr-php
المصادقة والترخيصالبرمجة النصية والأتمتةأمن الويبالأدوات والمكوناتأمن واجهات برمجة التطبيقات
GitHubeddiejibson/limitrr-php

limitrr-php

تحديد معدل أفضل لطلبات PHP باستخدام Redis.

عرض المستودع
206منذ 6 سنواتتمت المراجعة من قبل Kitploit

الأكثر شعبية

عرض الكل →

اكتشف الأدوات الأكثر استخدامًا من قبل مجتمعنا.

استكشف جميع الأدوات

تصفح مجموعتنا من الأدوات

عرض جميع الأدوات →
مشاركة
chae

تحديد معدل خفيف داخل PHP باستخدام Redis.

مكتبة Limitrr PHP مستوحاة بشكل كبير من مكتبتي الأخرى، Limitrr، التي أُنشئت لـ NodeJS. اطّلع عليها هنا

تتيح مكتبة Limitrr PHP للمستخدمين دمج تحديد معدل الطلبات بسهولة داخل تطبيقاتهم. وعلى عكس الحزم المماثلة الأخرى، تتيح هذه الأداة للمستخدم تحديد الحد ليس فقط حسب عدد الطلبات، بل أيضًا حسب عدد الإجراءات المكتملة (مثل السماح بإنشاء عدد معين من الحسابات بنجاح خلال فترة زمنية)، مع إمكانية تقييد ذلك بخيارات مخصصة. بالإضافة إلى ذلك، يمكن استخدام مميّزات مخصصة — لم يعد عليك الاقتصار على تحديد الحد حسب عنوان IP الخاص بالمستخدم.

توفر هذه المكتبة أيضًا دالة وسيطة (middleware) لتحديد معدل الطلبات بسهولة على المسارات المختلفة التي قد تكون لديك في مشروع SlimPHP.

إذا أعجبك هذا المشروع، يُرجى وضع 🌟 عليه على GitHub.

طلبات السحب (Pull Requests) مرحَّب بها

التثبيت

يمكنك تثبيت مكتبة limitrr-php بتنفيذ الأمر التالي في الطرفية (بافتراض أن لديك composer مثبّتًا)

root@kitploit:~
composer require eddiejibson/limitrr-php "^1.0"

دليل سريع

الاستخدام الأساسي

root@kitploit:~
require "/vendor/autoload.php"; //Require composer's autoload

$options = [
    //Redis keystore information
    "redis" => [
        "host" => "666.chae.sh",
        "port" => 6379,
        "password" => "supersecret",
    ],
    "routes" => [
        "default" => [
            "requestsPerExpiry" => 5,
        ],
    ],

];

//Initialize the Limitrr class and pass the options defined above into it
//Note that the options are not required.
$limitrr = new \eddiejibson\limitrr\Limitrr($options);

//Various examples like this can be found further into the documentation,
//for each function.
$result = $limitrr->get(["discriminator" => $ip]);
echo $result["requests"] + " Requests";
echo $result["completed"] + " Completed";
//Note that this library is no means just for SlimPHP, it just happens to
//provide a middleware function for those who may need it.

//Usage within SlimPHP
$app = new Slim\App();

//Use the Limitrr SlimPHP middleware function, if you wish:
$app->add(new \eddiejibson\limitrr\RateLimitMiddleware($limitrr)); //Make sure to pass in the main Limitrr
//instance we defined above into the middleware function. This is mandatory.

//You can also add the get IP middleware function, it will append the user's real IP
//(behind Cloudflare or not) to the request.
$app->add(new \eddiejibson\limitrr\getIpMiddleware());

//Example usage within a route
$app->get("/hello/{name}", function ($request, $response, $args) {
    $name = $args["name"];
    $ip = $request->getAttribute('realip'); //Get the IP that was defined within Limitrr's get IP middleware function
    return $response->getBody()->write("Hello, ${name}. Your IP is ${ip}.");
});

//You do not have to app the middleware function to every single route, globally.
//You can do it indivually, too - along with passing options into such. Like so:
$app->get("/createUser/{name}", function ($request, $response, $args) {
    //Non intensive actions like simple verification will have a different limit to intensive ones.
    //and will only be measured in terms of each request via the middleware.
    //No further action is required.
    if (strlen($args["name"]) < 5) {
        //Dummy function creating user
        $res = $someRandomClass->registerUser();
        if ($res) {
            //Intensive actions like actually registering a user should have a
            //different limit to normal requests, hence the completedActionsPerExpiry option.
            //and should only be added to once this task has been completed fully
            //In this example, we will be limiting the amount of completed actions a certain IP can make.
            //Anything can be passed in here, however. For example, a email address or user ID.
            //$request->getAttribute('realip') was determined by calling the middleware earlier - getIpMiddleware()
            $limitrr->complete(["discriminator"] => $ip);
        }
    }
})->add(new \eddiejibson\limitrr\RateLimitMiddleware($limitrr, ["route"=>"createUser"]));
//You can also pass the route name within the limitrr middleware function

$app->run();

الحصول على قيمة مفتاح معيّن

limitrr->get()

الإرجاع: Array

root@kitploit:~
$limitrr->get([
    "discriminator" => $discriminator, //Required
    "route" => $route, //Not required, default is assumed
    "type" => $type //Not required
]);
معاملات ->get()

يجب تمريرها إلى الدالة عبر مصفوفة (array)

  • discriminator: مطلوب حيث يكون المميِّز هو الشيء الذي يتم تحديد الحد له (مثل عدد معيّن من الإجراءات المكتملة لكل مميِّز)
  • route: String من أي مسار يجب استرجاع القيم؟ إذا لم يتم تعيينه، سيتم الحصول على العدادات من المسار default
  • type: String بدلاً من استرجاع القيمتين معًا، يمكنك تحديد إما requests أو completed في هذا المفتاح وسيتم عندها إرجاع القيمة المطلوبة فقط كعدد صحيح.
أمثلة على ->get()
root@kitploit:~
$limitrr->get([
    "discriminator" => $discriminator,
    "type" => $type,
    "route" => $route
]); //Besides discriminator, all parameters are optional.
//If type is not passed into the function, it will
//return both the amount of requests and completed actions

//Where discriminator is the thing being limited
//e.g x amount of completed actions/requests per discriminator
$limitrr->get(["discriminator" => $discriminator]);

//This tends to be the user's IP.
$limitrr->get(["discriminator" => $ip]);
//This will return both the amount of requests and completed actions stored under the
//discriminator provided in an object. You can handle like this:
$result = $limitrr->get(["discriminator" => $ip]);
echo $result["requests"] + " Requests";
echo $result["completed"] + " Completed";

//The above example would get the request and completed task count from the default
//route. If you would like to retrieve values from a different route, you can specify
//this as well. It can be done like this:
$result = $limitrr->get(["discriminator" => $ip, "route" => "exampleRouteName"]);
echo $result["requests"] . " Requests made through the route exampleRouteName";
echo $result["completed"] . " Completed Tasks made through the route exampleRouteName";

//You may also only fetch only one type of value - instead of both requests and completed.
$result = $limitrr->get(["discriminator" => $ip, "route" => "exampleRouteName", "type" => "completed"]);
echo $result["completed"] . " Completed tasks made through the route exampleRouteName";

عدّاد الإجراء/المهمة المكتملة

limitrr->complete()

الإرجاع: Integer

root@kitploit:~
$limitrr->get([
    "discriminator" => $discriminator, //Required
    "route" => $route, //Not required, default is assumed
]);
معاملات ->complete()

يجب تمريرها إلى الدالة عبر مصفوفة (array)

  • discriminator: مطلوب حيث يكون المميِّز هو الشيء الذي يتم تحديد الحد له (مثل عدد معيّن من الإجراءات المكتملة لكل مميِّز)
  • route: String في أي مسار يجب إدراج القيم؟ إذا لم يتم تعيينه، سيتم الحصول على العدادات من المسار default

إزالة القيم من مفاتيح طلبات/إجراءات مكتملة معيّنة

limitrr->reset()

الإرجاع: Boolean

root@kitploit:~
$limitrr->reset([
    "discriminator" => $discriminator, //Required
    "route" => $route, //Not required, default is assumed,
    "type" => $type //Not required
]);
معاملات ->reset()

يجب تمريرها إلى الدالة عبر مصفوفة (array)

  • discriminator: مطلوب حيث يكون المميِّز هو الشيء الذي يتم تحديد الحد له (مثل عدد معيّن من الإجراءات المكتملة لكل مميِّز)
  • route: String من أي مسار يجب إعادة تعيين القيم؟ إذا لم يتم تعيينه، سيتم إعادة تعيين العدادات من المسار default
  • type: String أي عدّاد تريد إعادة تعيينه؟ requests أم completed؟ إذا لم يتم تعيينه، ستتم إزالة كلاهما.
root@kitploit:~
//Where discriminator is the thing being limited
//e.g x amount of completed actions/requests per discriminator
//This will remove both the amount of requests and completed action count
$limitrr->reset(["discriminator" => $discriminator]);

//This tends to be the user's IP.
$limitrr->reset(["discriminator" => $ip]);

//If you wish to reset counts from a particular route, this can be done as well.
//As the type is not specified, it will remove both the request and completed count
$result = $limitrr->reset([
    "discriminator" => $ip,
    "route" => "exampleRouteName"
]);
if ($result) {
    echo "Requests removed from the route exampleRouteName";
} else {
    //Do something else
}

//If you want to remove either one of the amount of requests or completed actions.
//but not the other, this can be done as well.
//The value passed in can either be "requests" or "completed".
//In this example, we will be removing the request count for a certain IP
$result = $limitrr->reset([
    "discriminator" => $ip,
    "type" => "requests"
]);
if ($result) {
    echo "Request count for the specified IP were removed"
} else {
    //do something else
}

الإعدادات

redis

مطلوب: false

النوع: Array أو String

الوصف: معلومات الاتصال بـ Redis.

إما مرر سلسلة نصية تحتوي على URI لمثيل redis أو كائنًا يحتوي على معلومات الاتصال:

  • port: Integer منفذ Redis. القيمة الافتراضية: 6379
  • host: String اسم مضيف Redis. القيمة الافتراضية: "127.0.0.1"
  • password: String كلمة مرور Redis. القيمة الافتراضية: ""
  • database: Integer قاعدة بيانات Redis. القيمة الافتراضية: 0

مثال على مصفوفة/سلسلة redis التي يمكن تمريرها إلى Limitrr

root@kitploit:~
    //Pass in a string containing a redis URI.
    "redis" => "redis://127.0.0.1:6379/0"
    //Alternatively, use an array with the connection information.
    "redis" => [
        "port" => 6379, //Redis Port. Required: false. Defaults to 6379
        "host" => "127.0.0.1", //Redis hostname. required: False. Defaults to "127.0.0.1".
        "password" => "mysecretpassword1234", //Redis password. Required: false. Defaults to null.
        "database" => 0 //Redis database. Required: false. Defaults to 0.
    ]

options

مطلوب: false

النوع: Array

الوصف: خيارات متنوعة متعلقة بـ Limitrr.

  • keyName: String اسم المفتاح الذي ستُخزَّن تحته جميع الطلبات. هذا أساسًا لأغراض شكلية ولا يؤثر كثيرًا. ومع ذلك، يجب تغييره عند كل تهيئة للفئة الرئيسية لمنع التعارض. القيمة الافتراضية: "limitrr"
  • errorStatusCode: Integer رمز الحالة الذي سيتم إرجاعه عندما يتم تقييد معدل طلبات المستخدم. القيمة الافتراضية: 429 (طلبات كثيرة جدًا)

مثال على كائن options الذي يمكن تمريره إلى Limitrr

root@kitploit:~
"options" => [
    "keyName" => "myApp", //The keyname all of the requests will be stored under. Required: false. Defaults to "limitrr"
    "errorStatusCode" => 429 //Should important errors such as failure to connect to the Redis keystore be caught and displayed?
]

routes

مطلوب: false

النوع: Array

الوصف: تحديد قيود المسارات.

داخل كائن routes، يمكنك تعريف مسارات منفصلة متعددة وتعيين قواعد مخصصة داخلها. القواعد المخصصة التي يمكنك تعيينها هي:

  • requestsPerExpiry: Integer كم عدد الطلبات التي يمكن قبولها حتى يتم تقييد معدل طلبات المستخدم؟ القيمة الافتراضية: 100
  • completedActionsPerExpiry: Integer كم عدد الإجراءات المكتملة التي يمكن قبولها حتى يتم تقييد معدل طلبات المستخدم؟ هذا مفيد لإجراءات معينة مثل تسجيل مستخدم - يمكن السماح بعدد معين من الطلبات، لكن بعدد مختلف (أصغر بوضوح) من "الإجراءات المكتملة". لذلك إذا تم تسجيل مستخدمين بنجاح عدة مرات مؤخرًا تحت نفس عنوان IP (أو مميّز آخر)، يمكن تقييد معدل طلباتهم. قد يُسمح لهم بـ 100 طلب لكل فترة انتهاء معينة للتحقق العام وما شابه، ولكن فقط لجزء صغير من ذلك للإجراءات المكثفة. القيمة الافتراضية: القيمة في requestsPerExpiry أو 5 إذا لم تُعيَّن.
  • expiry: Integer كم من الوقت يجب تخزين الطلبات (بالثواني) قبل إعادتها إلى 0؟ إذا تم تعيينها إلى -1، فلن تنتهي صلاحية القيم أبدًا وستبقى على هذا النحو إلى أجل غير مسمى أو يجب إزالتها يدويًا. القيمة الافتراضية: 900 (15 دقيقة)
  • completedExpiry: Integer كم من الوقت يجب تخزين "الإجراءات المكتملة" (مثل عدد المستخدمين المسجلين من عنوان IP معين أو مميّز آخر) بالثواني قبل إعادتها إلى 0؟ إذا تم تعيينها إلى -1، فلن تنتهي صلاحية هذه القيم أبدًا وستبقى على هذا النحو إلى أجل غير مسمى أو يجب إزالتها يدويًا. القيمة الافتراضية: القيمة في expiry أو 900 (15 دقيقة) إذا لم تُعيَّن.
  • errorMsgs: Object رسائل خطأ منفصلة لحالات "عدد الطلبات كبير جدًا" و"عدد الإجراءات المكتملة كبير جدًا". وقد أُعطيت اسمي المفتاحين "requests" و"actions" على التوالي. سيتم إرجاع هذه الرسالة إلى المستخدم عندما يتم تقييد معدل طلباته. إذا لم يتم تعيين سلسلة نصية في requests، فستكون القيمة الافتراضية . علاوة على ذلك، إذا لم يتم تعيين قيمة في ، سيتم استخدام السلسلة الموجودة في . أو إذا لم يتم تعيين تلك أيضًا، فستكون هي قيمتها.

مثال على مصفوفة routes

root@kitploit:~
"routes" => [
    //Overwrite default route rules - not all of the keys must be set,
    //only the ones you wish to overwrite
    "default" => [
        "expiry": 1000
    ],
    "exampleRoute" => [
        "requestsPerExpiry" => 100,
        "completedActionsPerExpiry" => 5,
        "expiry" => 900,
        "completedExpiry" => 900,
        "errorMsgs" => [
            "requests" => "As you have made too many requests, you are being rate limited.",
            "completed" => "As you performed too many successful actions, you have been rate limited."
        ]
    ],
    //If not all keys are set, they will revert to
    //the default values
    "exampleRoute2" => [
        "requestsPerExpiry" => 500
    ]
]
تنزيل الأداة
"As you have made too many requests, you are being rate limited."
completed
requests
"As you performed too many successful actions, you have been rate limited."