Skip to content

A small library to help run PHP local server easily and quickly.

License

Notifications You must be signed in to change notification settings

Ahmard/php-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  • 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 😎