{"id":13411429,"url":"https://github.com/thenlabs/http-server","last_synced_at":"2026-01-11T12:50:32.130Z","repository":{"id":57068332,"uuid":"308719612","full_name":"thenlabs/http-server","owner":"thenlabs","description":"A HTTP Server written in PHP with help of the Symfony components.","archived":false,"fork":false,"pushed_at":"2021-10-23T22:15:49.000Z","size":2327,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"1.2","last_synced_at":"2024-07-31T20:45:48.801Z","etag":null,"topics":["http-server","monolog","php","symfony-httpfoundation","symfony-mime","symfony-router"],"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/thenlabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-30T19:00:19.000Z","updated_at":"2023-07-08T03:23:21.000Z","dependencies_parsed_at":"2022-08-24T10:20:32.274Z","dependency_job_id":null,"html_url":"https://github.com/thenlabs/http-server","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thenlabs%2Fhttp-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thenlabs%2Fhttp-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thenlabs%2Fhttp-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thenlabs%2Fhttp-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thenlabs","download_url":"https://codeload.github.com/thenlabs/http-server/tar.gz/refs/heads/1.2","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243618607,"owners_count":20320265,"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":["http-server","monolog","php","symfony-httpfoundation","symfony-mime","symfony-router"],"created_at":"2024-07-30T20:01:13.607Z","updated_at":"2026-01-11T12:50:32.088Z","avatar_url":"https://github.com/thenlabs.png","language":"PHP","funding_links":[],"categories":["Web Development"],"sub_categories":["PHP"],"readme":"\n# HttpServer\n\nA HTTP server written in PHP with help of the Symfony Components.\n\n\u003eIf you like this project gift us a ⭐.\n\n## Installation.\n\n    $ composer require thenlabs/http-server\n\n## Usage.\n\nCreate a file with the next example content:\n\n\u003eYou should change the content according to your needs.\n\n```php\n\u003c?php\n// run-server.php\n\nrequire __DIR__.'/vendor/autoload.php';\n\nuse ThenLabs\\HttpServer\\HttpServer;\n\n$config = [\n    'host' =\u003e '127.0.0.1',\n    'port' =\u003e 8080,\n    'document_root' =\u003e __DIR__.'/vendor/thenlabs/http-server/tests/Functional/document_root',\n];\n\n$server = new HttpServer($config);\n$server-\u003estart();\n\nwhile (true) {\n    $server-\u003erun();\n}\n```\n\nThis file should be executed like that:\n\n    $ php run-server.php\n\nOnce does it, we can navigate to the URL and we will see the respectively page.\n\n\u003eIn our example, we are serving the `index.html` file which is stored within the `tests/document_root` directory.\n\n![](demo.jpg)\n\n### Creating custom routes.\n\nThe HttpServer use the [Symfony Routing Component](https://github.com/symfony/routing) for handle the routing, therefore, you can use all the his possibilities.\n\nThe next example shown the way to creating a custom route which only can be access by a GET request.\n\n```php\n\u003c?php\n\nuse Symfony\\Component\\HttpFoundation\\Request;\nuse Symfony\\Component\\HttpFoundation\\Response;\n\n// ...\n\n$server-\u003eget('/article/{id}', function (Request $request, array $parameters): Response {\n    return new Response(\"This is the article {$parameters['id']}\");\n});\n\n// ...\n```\n\n### Using the logs.\n\nLike you can will verify, by default are will shows in the console the result of all server requests.\n\n![](console-logs.png)\n\nThe logs are created with help of the popular [Monolog](https://github.com/Seldaek/monolog) library.\n\nThe next example showns a way to put the logs in a file.\n\n```php\n\u003c?php\n\n// ...\nuse Monolog\\Handler\\StreamHandler;\n\n// ...\n$server-\u003egetLogger()-\u003epushHandler(new StreamHandler('/path/to/file.logs'));\n```\n\n## Development.\n\n### Running the tests.\n\nStart the selenium server.\n\n    $ java -jar path/to/selenium-server-standalone-x.y.z.jar\n\nRun PHPUnit.\n\n    $ ./vendor/bin/pyramidal\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthenlabs%2Fhttp-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthenlabs%2Fhttp-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthenlabs%2Fhttp-server/lists"}