Skip to content

Latest commit

 

History

History
71 lines (49 loc) · 1.27 KB

README.md

File metadata and controls

71 lines (49 loc) · 1.27 KB

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 😎