A small library to help run PHP servers easily and quickly.
composer require ahmard/php-server --dev
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 😎