Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thenlabs/http-server
A HTTP Server written in PHP with help of the Symfony components.
https://github.com/thenlabs/http-server
http-server monolog php symfony-httpfoundation symfony-mime symfony-router
Last synced: about 2 months ago
JSON representation
A HTTP Server written in PHP with help of the Symfony components.
- Host: GitHub
- URL: https://github.com/thenlabs/http-server
- Owner: thenlabs
- License: mit
- Created: 2020-10-30T19:00:19.000Z (almost 4 years ago)
- Default Branch: 1.2
- Last Pushed: 2021-10-23T22:15:49.000Z (almost 3 years ago)
- Last Synced: 2024-05-16T11:26:24.655Z (4 months ago)
- Topics: http-server, monolog, php, symfony-httpfoundation, symfony-mime, symfony-router
- Language: PHP
- Homepage:
- Size: 2.22 MB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- cuban-opensource - HttpServer
README
# HttpServer
A HTTP server written in PHP with help of the Symfony Components.
>If you like this project gift us a ⭐.
## Installation.
$ composer require thenlabs/http-server
## Usage.
Create a file with the next example content:
>You should change the content according to your needs.
```php
'127.0.0.1',
'port' => 8080,
'document_root' => __DIR__.'/vendor/thenlabs/http-server/tests/Functional/document_root',
];$server = new HttpServer($config);
$server->start();while (true) {
$server->run();
}
```This file should be executed like that:
$ php run-server.php
Once does it, we can navigate to the URL and we will see the respectively page.
>In our example, we are serving the `index.html` file which is stored within the `tests/document_root` directory.
![](demo.jpg)
### Creating custom routes.
The HttpServer use the [Symfony Routing Component](https://github.com/symfony/routing) for handle the routing, therefore, you can use all the his possibilities.
The next example shown the way to creating a custom route which only can be access by a GET request.
```php
get('/article/{id}', function (Request $request, array $parameters): Response {
return new Response("This is the article {$parameters['id']}");
});// ...
```### Using the logs.
Like you can will verify, by default are will shows in the console the result of all server requests.
![](console-logs.png)
The logs are created with help of the popular [Monolog](https://github.com/Seldaek/monolog) library.
The next example showns a way to put the logs in a file.
```php
getLogger()->pushHandler(new StreamHandler('/path/to/file.logs'));
```## Development.
### Running the tests.
Start the selenium server.
$ java -jar path/to/selenium-server-standalone-x.y.z.jar
Run PHPUnit.
$ ./vendor/bin/pyramidal