https://github.com/ahmard/php-server
A small library to help run PHP local server easily and quickly.
https://github.com/ahmard/php-server
php php-builtin-server php-server php-servers php8 reactphp-server
Last synced: about 1 month ago
JSON representation
A small library to help run PHP local server easily and quickly.
- Host: GitHub
- URL: https://github.com/ahmard/php-server
- Owner: Ahmard
- License: mit
- Created: 2021-09-04T20:39:35.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-03-26T21:11:11.000Z (about 1 year ago)
- Last Synced: 2025-02-20T05:17:19.324Z (2 months ago)
- Topics: php, php-builtin-server, php-server, php-servers, php8, reactphp-server
- Language: PHP
- Homepage:
- Size: 39.1 KB
- Stars: 12
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP Server
A small library to help run PHP servers easily and quickly.
## Installation
```
composer require ahmard/php-server --dev
```## Usage
### PHP Built-In Server
An implementation of [Built-In Server](https://www.php.net/manual/en/features.commandline.webserver.php)
- With document root
```php
use PHPServer\BuiltIn\Server;Server::create('127.0.0.1', '9900')
->setDocumentRoot(__DIR__)
->start()
->logOutputToConsole();
```- Route request to single entry file
```php
use PHPServer\BuiltIn\Server;Server::create('127.0.0.1', '9900')
->setRouterScript(__DIR__ . 'public/index.php')
->start();
```- Provide callable to be invoked when request is received
```php
use PHPServer\BuiltIn\Server;Server::create('127.0.0.1', '9900')
->onRequest(fn() => var_dump('Request Received'))
->start();
```- Using multiple workers
```php
use PHPServer\BuiltIn\Server;Server::create('127.0.0.1', '9900')
->setWorkers(2)
->onRequest(fn() => var_dump('Request Received'))
->start();
```- Use preferred php version/executable
```php
use PHPServer\BuiltIn\Server;Server::create('127.0.0.1', '9900')
->setWorkers(2)
->setPHPExecutable('/usr/bin/php8.0')
->onRequest(fn() => var_dump('Request Received'))
->start();
```Enjoy 😎