ahmard / php-server
A small library to help run PHP servers easily and quickly.
0.1.1
2024-03-26 21:10 UTC
Requires
- php: ^8.1
- ext-pdo: *
- nette/utils: ^4.0
- opis/closure: ^3.6
- react/child-process: ^0.6.5
- symfony/console: ^7.0
Requires (Dev)
- phpstan/phpstan: ^1.10
- symfony/var-dumper: ^7.0
README
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
- With document root
use PHPServer\BuiltIn\Server; Server::create('127.0.0.1', '9900') ->setDocumentRoot(__DIR__) ->start() ->logOutputToConsole();
- Route request to single entry file
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
use PHPServer\BuiltIn\Server; Server::create('127.0.0.1', '9900') ->onRequest(fn() => var_dump('Request Received')) ->start();
- Using multiple workers
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
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 😎