{"id":20540586,"url":"https://github.com/utopia-php/abuse","last_synced_at":"2026-01-16T14:31:09.163Z","repository":{"id":45257362,"uuid":"183948411","full_name":"utopia-php/abuse","owner":"utopia-php","description":"Lite \u0026 fast micro PHP abuse library that is **easy to use**.","archived":false,"fork":false,"pushed_at":"2026-01-15T02:10:36.000Z","size":475,"stargazers_count":26,"open_issues_count":2,"forks_count":21,"subscribers_count":7,"default_branch":"main","last_synced_at":"2026-01-15T07:58:20.239Z","etag":null,"topics":["abuse","hacktoberfest","php","utopia","utopia-framework"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/utopia-php.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-04-28T19:11:19.000Z","updated_at":"2026-01-15T02:09:55.000Z","dependencies_parsed_at":"2022-08-12T11:51:02.528Z","dependency_job_id":"4dd619d7-edc0-48fb-bfab-edfba396358b","html_url":"https://github.com/utopia-php/abuse","commit_stats":{"total_commits":170,"total_committers":17,"mean_commits":10.0,"dds":0.7941176470588236,"last_synced_commit":"9360a026d18809e35523b254ab57e51055008203"},"previous_names":[],"tags_count":78,"template":false,"template_full_name":null,"purl":"pkg:github/utopia-php/abuse","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Fabuse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Fabuse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Fabuse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Fabuse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/utopia-php","download_url":"https://codeload.github.com/utopia-php/abuse/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utopia-php%2Fabuse/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28479396,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abuse","hacktoberfest","php","utopia","utopia-framework"],"created_at":"2024-11-16T01:16:24.608Z","updated_at":"2026-01-16T14:31:09.151Z","avatar_url":"https://github.com/utopia-php.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Utopia Abuse\n\n[![Build Status](https://travis-ci.org/utopia-php/abuse.svg?branch=master)](https://travis-ci.com/utopia-php/abuse)\n![Total Downloads](https://img.shields.io/packagist/dt/utopia-php/abuse.svg)\n[![Discord](https://img.shields.io/discord/564160730845151244)](https://appwrite.io/discord)\n\nUtopia framework abuse library is simple and lite library for managing application usage limits. This library is aiming to be as simple and easy to learn and use. This library is maintained by the [Appwrite team](https://appwrite.io).\n\nAlthough this library is part of the [Utopia Framework](https://github.com/utopia-php/framework) project it is dependency free, and can be used as standalone with any other PHP project or framework.\n\n## Getting Started\n\nInstall using composer:\n\n```bash\ncomposer require utopia-php/abuse\n```\n\n**Time Limit Abuse**\n\nThe time limit abuse allow each key (action) to be performed [X] times in given time frame.\nThis adapter uses a MySQL / MariaDB to store usage attempts. Before using it create the table schema as documented in this repository (./data/schema.sql)\n\n### Database adapter\n\n```php\n\u003c?php\n\nrequire_once __DIR__ . '/../../vendor/autoload.php';\n\nuse Utopia\\Abuse\\Abuse;\nuse Utopia\\Abuse\\Adapters\\TimeLimit;\nuse Utopia\\Cache\\Adapter\\None as NoCache;\nuse Utopia\\Cache\\Cache;\nuse Utopia\\Database\\Adapter\\MySQL;\nuse Utopia\\Database\\Database;\n\n$dbHost = '127.0.0.1';\n$dbUser = 'travis';\n$dbPass = '';\n$dbPort = '3306';\n\n$pdo = new PDO(\"mysql:host={$dbHost};port={$dbPort};charset=utf8mb4\", $dbUser, $dbPass, [\n    PDO::ATTR_TIMEOUT =\u003e 3, // Seconds\n    PDO::ATTR_PERSISTENT =\u003e true,\n    PDO::ATTR_DEFAULT_FETCH_MODE =\u003e PDO::FETCH_ASSOC,\n    PDO::ATTR_ERRMODE =\u003e PDO::ERRMODE_EXCEPTION,\n    PDO::ATTR_EMULATE_PREPARES =\u003e true,\n    PDO::ATTR_STRINGIFY_FETCHES =\u003e true,\n]);\n\n$db = new Database(new MySQL($pdo), new Cache(new NoCache()));\n$db-\u003esetNamespace('namespace');\n\n// Limit login attempts to 10 time in 5 minutes time frame\n$adapter    = new TimeLimit('login-attempt-from-{{ip}}', 10, (60 * 5), $db);\n\n$adapter-\u003esetup(); //setup database as required\n$adapter-\u003esetParam('{{ip}}', '127.0.0.1')\n;\n\n$abuse      = new Abuse($adapter);\n\n// Use vars to resolve adapter key\n\nif($abuse-\u003echeck()) {\n    throw new Exception('Service was abused!'); // throw error and return X-Rate limit headers here\n}\n```\n\n### Appwrite TablesDB adapter\n\n```php\n\u003c?php\n\nrequire_once __DIR__ . '/../../vendor/autoload.php';\n\nuse Utopia\\Abuse\\Abuse;\nuse Utopia\\Abuse\\Adapters\\TimeLimit\\Appwrite\\TablesDB as TablesDBAdapter;\nuse Appwrite\\Client;\n\n$client = (new Client())\n    -\u003esetEndpoint('[YOUR_ENDPOINT]')\n    -\u003esetProject('[YOUR_PROJECT_ID]')\n    -\u003esetKey('[YOUR_API_KEY]');\n$databaseId = 'abuse';\n\n// Limit login attempts to 10 time in 5 minutes time frame\n$adapter = new TablesDBAdapter('login-attempt-from-{{ip}}', 10, (60 * 5), $client, $databaseId);\n\n$adapter-\u003esetup(); //setup database as required\n$adapter-\u003esetParam('{{ip}}', '127.0.0.1');\n\n$abuse = new Abuse($adapter);\n\n// Use vars to resolve adapter key\n\nif($abuse-\u003echeck()) {\n    throw new Exception('Service was abused!'); // throw error and return X-Rate limit headers here\n}\n```\n\n**ReCaptcha Abuse**\n\nThe ReCaptcha abuse controller is using Google ReCaptcha service to detect when service is being abused by bots.\nTo use this adapter you need to create an API key from the Google ReCaptcha service [admin console](https://www.google.com/recaptcha/admin).\n\n```php\n\u003c?php\n\nrequire_once __DIR__ . '/../../vendor/autoload.php';\n\nuse Utopia\\Abuse\\Abuse;\nuse Utopia\\Abuse\\Adapters\\ReCaptcha;\n\n// Limit login attempts to 10 time in 5 minutes time frame\n$adapter    = new ReCaptcha('secret-api-key', $_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);\n$abuse      = new Abuse($adapter);\n\nif($abuse-\u003echeck()) {\n    throw new Exception('Service was abused!'); // throw error and return X-Rate limit headers here\n}\n```\n\n*Notice: The code above is for example purpose only. It is always recommended to validate user input before using it in your code. If you are using a load balancer or any proxy server you might need to get user IP from the HTTP_X_FORWARDE‌​D_FOR header.*\n\n## System Requirements\n\nUtopia Framework requires PHP 8.0 or later. We recommend using the latest PHP version whenever possible.\n\n## Copyright and license\n\nThe MIT License (MIT) [http://www.opensource.org/licenses/mit-license.php](http://www.opensource.org/licenses/mit-license.php)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Futopia-php%2Fabuse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Futopia-php%2Fabuse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Futopia-php%2Fabuse/lists"}