{"id":36384328,"url":"https://github.com/phpwatch/fast404","last_synced_at":"2026-01-11T15:00:48.711Z","repository":{"id":39710892,"uuid":"260443257","full_name":"PHPWatch/Fast404","owner":"PHPWatch","description":"A PSR-7 middleware to return 404 errors fast for requests that are not worth returning a fancy 404 error.","archived":false,"fork":false,"pushed_at":"2024-11-29T06:52:15.000Z","size":30,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-19T18:01:39.574Z","etag":null,"topics":["middleware"],"latest_commit_sha":null,"homepage":"https://php.watch","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/PHPWatch.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-05-01T11:29:47.000Z","updated_at":"2024-11-29T06:52:19.000Z","dependencies_parsed_at":"2023-12-29T10:46:27.217Z","dependency_job_id":null,"html_url":"https://github.com/PHPWatch/Fast404","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/PHPWatch/Fast404","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PHPWatch%2FFast404","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PHPWatch%2FFast404/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PHPWatch%2FFast404/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PHPWatch%2FFast404/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PHPWatch","download_url":"https://codeload.github.com/PHPWatch/Fast404/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PHPWatch%2FFast404/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28309519,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T14:58:17.114Z","status":"ssl_error","status_checked_at":"2026-01-11T14:55:53.580Z","response_time":60,"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":["middleware"],"created_at":"2026-01-11T15:00:23.781Z","updated_at":"2026-01-11T15:00:48.699Z","avatar_url":"https://github.com/PHPWatch.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fast 404\n\nQuickly terminate an HTTP request with a `404 Not Found` response for static resources.\n\n[![Latest Stable Version](https://poser.pugx.org/phpwatch/fast404/v)](https://packagist.org/packages/phpwatch/fast404) ![CI](https://github.com/PHPWatch/Fast404/workflows/CI/badge.svg?branch=master) [![Total Downloads](https://poser.pugx.org/phpwatch/fast404/downloads)](https://packagist.org/packages/phpwatch/fast404) [![License](https://poser.pugx.org/phpwatch/fast404/license)](https://github/phpwatch/fast404)\n\n`phpwatch/fast404` is a library/middleware that you can to quickly terminate an HTTP request with a `404 Not Found` response.\n\nThe use case is a framework that handles all HTTP requests via a router, and returning a quick 404 message to static resources such as `.jpg` or `.png`. This prevents the framework from initializing rendering engines, database connections, etc to serve these types of requests. \n\nIt is common that PHP frameworks use a router to handle incoming HTTP requests. Web server forwards all requests to the PHP framework (often to the `index.php` file). This has the side-effect of static resources such as `.jpg` or `.png` requests being routed to the PHP framework as well. \n\nFrameworks can generate a nice 404 Not Found error page, it is a waste of resources to generate nice error pages for images, videos, and other embeded content that are not the main URL the user accessed. \n\nThis package comes with configurable but sensible defaults, and when added as a middleware, it is executed early in the request, and short-circuits the rest of the bootstrap process and returns a quick and dirty \"Not Found\" page with the proper HTTP header. This can reduce the overhead by not having to connect to the database or fire up a rendering engine.\n\nNote that the rest of the execution will be terminated with a PHP `die()` call. If you want to log the error messages via the framework events or other middleware, this package is not for you. \n\n### Installation\n\n```bash\ncomposer require phpwatch/fast404\n```\n\n### Usage\n\nYou need to execute the provided middleware within your framework. \nHere is an example for Slim v3:\n\n**1. Add `Fast404Middleware` class to the Container**\n\n```php\n\u003c?php\n$container[Fast404Middleware::class] = static function (Container $container) {  \n  return new Fast404Middleware();  \n};\n```\n\n**2. Use the middleware in individual routes/groups, or for the whole application**\n\n```php\n\u003c?php\nuse PHPWatch\\Fast404\\Fast404Middleware;\n\n$app-\u003eadd(Fast404Middleware::class); // For whole app\n$app-\u003eget/users/{username},...)-\u003eadd(Fast404Middleware::class); // Or, for individual routes\n```\n\n\n### Configuration\n\nYou can declare settings when the `Fast404Middleware` is instantiated:\n\n```php\n\u003c?php\nnew Fast404Middleware(string $error_message = 'Not found', string $regex = null, ?string $exclude_regex = null)\n```\n\n - `$error_message`: Text for the error message. You can use anything here, including HTML content. Note that this library does not set a `content-type` header.\n - `$regex`: A valid regular expression including the delimiters. The default (below) is fast-404 a list of pre-configured file extensions. \n - `$exclude_regex`: A regular expression that is run if provided, and if it matches, the request is _allowed_. You can combine this regular expression as a negative lookahead/behind match in `$regex` too, but that would make the regular expression a bit difficult to read. \n\n**Default match**\n\nBy default, the following regular expression is used. It matches a list of pre-configured common extensions. \n\n```regex\n/\\.(?:js|css|jpg|jpeg|gif|png|ico|exe|bin|dmg)$/i\n```\n\nConfigure it to your hearts desire; Just make sure that you absolutely don't want the framework to continue the requests for these types of extensions. \n\n## PSR-15 / PSR-7\nAs of now, there is a `__invoke` method that accepts PSR-7 `ServerRequestInterface` object. This makes this library immediately compatible with Slim v3. Proper PSR-15 support is in the works, and will be compatible with Slim v4 and any other compatible dispatcher. \n\n## Log 404 errors\nThis library immediately terminates the request with a configurable error message and an HTTP 404 error. There will be no logging. If you want your web server to log these same errors, it should not have handed over the request to the framework. \n\n## I really need 404 logging\nNo. Get out and implement this yourself. This is a 40 LOC package. This README is **four** times larger than the code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpwatch%2Ffast404","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphpwatch%2Ffast404","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpwatch%2Ffast404/lists"}