{"id":24540680,"url":"https://github.com/mistralys/errorcode-incrementor","last_synced_at":"2025-03-16T05:43:29.202Z","repository":{"id":57017586,"uuid":"336392279","full_name":"Mistralys/errorcode-incrementor","owner":"Mistralys","description":"Simple PHP script that increments counters via HTTP requests or programmatically.","archived":false,"fork":false,"pushed_at":"2021-03-19T14:51:20.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-22T18:14:37.966Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/Mistralys.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-05T21:23:07.000Z","updated_at":"2021-03-19T14:50:18.000Z","dependencies_parsed_at":"2022-08-22T11:31:21.357Z","dependency_job_id":null,"html_url":"https://github.com/Mistralys/errorcode-incrementor","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Ferrorcode-incrementor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Ferrorcode-incrementor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Ferrorcode-incrementor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Ferrorcode-incrementor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mistralys","download_url":"https://codeload.github.com/Mistralys/errorcode-incrementor/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243830914,"owners_count":20354850,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2025-01-22T18:14:40.215Z","updated_at":"2025-03-16T05:43:29.182Z","avatar_url":"https://github.com/Mistralys.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Error code / counter incrementor\n\nSimple PHP script that increments a counter when accessed, and the displays the current count.\n\nCan also be used programmatically when used as a project's composer dependency.\n\n## Installation\n\n- Check out in a folder of your choice in the document root of your webserver\n- Rename `config-local.dist.php` to `config-local.php`\n- Ensure that the `storage` folder is writable by the script\n- Edit the required settings in the file, set up the counters you wish to use (see Configuration)\n\n## Configuration\n\n### Password\n\nThe counter is password protected to avoid someone hogging the server in a DOS attack, since it causes a write operation on the hard drive, and can thus create a heavy system load in such a context.\n\nEven if this seems like a trivial operation, take care to choose a good password.\n\n### The counters list\n\nThe counters array in `config-local.php` is very simple. Let's say you have two applications for which you want to maintain error code counters, called \"Mistral\" and \"Tramontane\" (Wind names). The counters list would look like this:\n\n```php\n\u003c?php\n$counters = array(\n    'Mistral' =\u003e 0,\n    'Tramontane' =\u003e 520 // start at #520\n);\n```\n\nNote: There is no limitation on the characters used in the names - you can safely use UTF8 and special characters if you wish. \n\n### Update delay\n\nSee Security \u003e Minimum update delays. \n\n## Quick start\n\nTo start checking counter values, point your browser to where the script is located, and use the following GET parameters:\n\n- View a counter: `/path/?pw=****\u0026counter=(name)`\n- Increment a counter: `/path/?pw=****\u0026counter=(name)\u0026increment=yes`\n\nBoth will display the current value of the selected counter.\n\n## Security\n\n### Minimum update delays\n\nTo mitigate DOS attacks or avoid spamming the counters, an update delay is enforced between incrementing counters. By default, it is only possible to increment a counter every 10 seconds.\n\nThe absolute minimum is enforced at 1 second.\n\nNote: The delay works separately for each counter, and is only used when incrementing.\n\n### HTTPS recommended\n\nSince the counter uses a password, it is a bad idea to use it over HTTP, as it is relatively easy to intercept the password in the requests. Use a webserver with an SSL certificate, and serve the script using an HTTPS connection.\n\n## Error handling\n\nThe script will send an HTTP status code when something goes wrong, with a descriptive status text.\n\nPossible errors:\n\n- `401` Wrong or no password\n- `400` No counter name specified\n- `404` Specified counter does not exist\n- `403` Minimum update delay not respected\n- `500` Counter data cannot be saved/loaded\n\n## Accessing counters programmatically\n\nThe `Counters` class can be used independently of serving the counters via HTTP requests. This means that you can simply require this package as a dependency in your project, and use the `Counters` class there.\n\n### Getting a counter value\n\n```php\n\u003c?php\n// The list of counters\n$counters = array(\n    'Test' =\u003e 0\n);\n\n// Create the collection with the path to the folder\n// where the files can be stored - must be writable.\n$collection = new \\Mistralys\\Counters\\Counters('./storage', $counters);\n\n// To avoid an exception, always check first\nif($collection-\u003ecounterExists('Test'))\n{\n    $number = $collection-\u003egetByName('Test')-\u003egetNumber();\n}  \n```\n\n### Incrementing a counter\n\n```php\n\u003c?php\n// The list of counters\n$counters = array(\n    'Test' =\u003e 0\n);\n\n// Create the collection with the path to the folder\n// where the files can be stored - must be writable.\n$collection = new \\Mistralys\\Counters\\Counters('./storage', $counters);\n\n// To avoid an exception, always check first\nif($collection-\u003ecounterExists('Test'))\n{\n    // Incrementing returns the new counter value\n    $newNumber = $collection-\u003egetByName('Test')-\u003eincrement();\n}  \n```\n\n### Fetching available counters\n\n```php\n\u003c?php\n// The list of counters\n$counters = array(\n    'Test' =\u003e 0\n);\n\n// Create the collection with the path to the folder\n// where the files can be stored - must be writable.\n$collection = new \\Mistralys\\Counters\\Counters('./storage', $counters);\n\n$counters = $collection-\u003egetCounters();\n\n// Display a list of counters and their values\nforeach($counters as $counter)\n{\n    echo $counter-\u003egetName().' = '.$counter-\u003egetNumber().PHP_EOL;\n}  \n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmistralys%2Ferrorcode-incrementor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmistralys%2Ferrorcode-incrementor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmistralys%2Ferrorcode-incrementor/lists"}