PHP Application Server: Run application with different types of Web server

Recommend this page to a friend!
  Info   View files Example   View files View files (31)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2021-09-15 (9 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 38 This week: 9All time: 10,210 This week: 27Up
Version License PHP version Categories
php-server 1.0.0Shareware5HTTP, PHP 5, Libraries
Description Author

This package can run applications with different types of the Web server.

It provides classes that can handle HTTP requests using different Web servers by routing the requests to given application scripts.

Currently, it supports the PHP built-in Web server and Web servers based on ReactPHP and Swoole.

Picture of Ahmad Mustapha
Name: Ahmad Mustapha <contact>
Classes: 14 packages by
Country: Nigeria Nigeria
Innovation award
Innovation award
Nominee: 5x

Details

PHP Server

A small library to help run PHP servers easily and quickly.

Installation

composer require ahmard/php-server

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();


### ReactPHP
An implementation of ReactPHP

use PHPServer\React\Server; use Psr\Http\Message\RequestInterface; use React\Http\Message\Response;

require 'vendor/autoload.php';

$handler = function (RequestInterface $request) {

$html = 'Welcome,<br/>';
$html .= "Method: {$request->getMethod()}<br/>";
$html .= "Route: {$request->getUri()->getPath()}";
return new Response(200, ['Content-Type' => 'text/html'], $html);

};

Server::create('127.0.0.1', 9001)

->onRequest($handler)
->start()
->logOutputToConsole();

### Swoole
An implementation of Swoole

use PHPServer\Swoole\Http\Request; use PHPServer\Swoole\Server;

require 'vendor/autoload.php';

$handler = function (Request $request) {

$html = 'Welcome,<br/>';
$html .= "Method: {$request->getMethod()}<br/>";
$html .= "Route: {$request->getUri()->getPath()}";
$request->response()->html($html);

};

Server::create('127.0.0.1', 9904)

->watchFilesystemChanges([__DIR__])
->onRequest($handler)
->setServerConfig([
    'enable_static_handler' => true,
    'http_parse_post' => true,
    'worker_num' => 8,
    'package_max_length' => 10 1024 1024
])
->start()
->logOutputToConsole();
  Files folder image Files  
File Role Description
Files folder imagebin (3 files)
Files folder imagesrc (11 files, 3 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file requests.http Data Auxiliary data
Accessible without login Plain text file test-builtin.php Example Example script
Accessible without login Plain text file test-react.php Example Example script
Accessible without login Plain text file test-swoole.php Example Example script

  Files folder image Files  /  bin  
File Role Description
  Accessible without login Plain text file built-in.php Example Example script
  Accessible without login Plain text file react.php Example Example script
  Accessible without login Plain text file swoole.php Example Example script

  Files folder image Files  /  src  
File Role Description
Files folder imageBuiltIn (1 file)
Files folder imageReact (1 file)
Files folder imageSwoole (3 files, 1 directory)
  Plain text file AbstractServer.php Class Class source
  Plain text file Env.php Class Class source
  Accessible without login Plain text file functions.php Aux. Auxiliary script
  Plain text file Kernel.php Class Class source
  Plain text file RunningServer.php Class Class source
  Plain text file ServerCommand.php Class Class source
  Plain text file ServerInfo.php Class Class source
  Plain text file ServerInterface.php Class Class source
  Plain text file ServerProcess.php Class Class source
  Plain text file StartedServerInterface.php Class Class source
  Plain text file Terminal.php Class Class source

  Files folder image Files  /  src  /  BuiltIn  
File Role Description
  Plain text file Server.php Class Class source

  Files folder image Files  /  src  /  React  
File Role Description
  Plain text file Server.php Class Class source

  Files folder image Files  /  src  /  Swoole  
File Role Description
Files folder imageHttp (4 files, 1 directory)
  Plain text file Console.php Class Class source
  Plain text file Kernel.php Class Class source
  Plain text file Server.php Class Class source

  Files folder image Files  /  src  /  Swoole  /  Http  
File Role Description
Files folder imageMiddlewares (1 file)
  Plain text file Middleware.php Class Class source
  Plain text file Request.php Class Class source
  Plain text file RequestMiddleware.php Class Class source
  Plain text file Response.php Class Class source

  Files folder image Files  /  src  /  Swoole  /  Http  /  Middlewares  
File Role Description
  Plain text file MiddlewareInterface.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:38
This week:9
All time:10,210
This week:27Up
For more information send a message to info at phpclasses dot org.