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

Overview

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)
    ->onRequest($handler)
    ->setServerConfig([
        'enable_static_handler' => true,
        'http_parse_post' => true,
        'worker_num' => 8,
        'package_max_length' => 10 * 1024 * 1024
    ])
    ->start()
    ->logOutputToConsole();

Swoole with filesystem watcher, this requires an installation of ahmard/swotch package.

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

require 'vendor/autoload.php';

Server::create('127.0.0.1', 9904)
    ->watchFilesystemChanges([__DIR__])
    ->onRequest(function (Request $request){
        $request->response()->html('Hello');
    })
    ->setServerConfig([
        'enable_static_handler' => true,
        'http_parse_post' => true,
        'worker_num' => 8,
        'package_max_length' => 10 * 1024 * 1024
    ])
    ->start()
    ->logOutputToConsole();
You might also like...
A small, modern, PSR-7 compatible PSR-17 and PSR-18 network library for PHP, inspired by Go's net package.

Net A small, modern, PSR-7 compatible PSR-17 and PSR-18 network library for PHP, inspired by Go's net package. Features: No hard dependencies; Favours

A small, modern, PSR-7 compatible PSR-17 and PSR-18 network library for PHP, inspired by Go's net package.

Net A small, modern, PSR-7 compatible PSR-17 and PSR-18 network library for PHP, inspired by Go's net package. Features: No hard dependencies; Favours

Configure Magento 2 to send email using Google App, Gmail, Amazon Simple Email Service (SES), Microsoft Office365 and many other SMTP (Simple Mail Transfer Protocol) servers
Configure Magento 2 to send email using Google App, Gmail, Amazon Simple Email Service (SES), Microsoft Office365 and many other SMTP (Simple Mail Transfer Protocol) servers

Magento 2 SMTP Extension - Gmail, G Suite, Amazon SES, Office 365, Mailgun, SendGrid, Mandrill and other SMTP servers. For Magento 2.0.x, 2.1.x, 2.2.x

API server and modernized control panel for PocketMine servers.

WebConsole API server and modernized control panel for PocketMine servers. The WebConsole plugin provides an HTTP API server that can be extended with

A PHP library that can be used manually as well as a CLI script that you can just run on your file

Run phpcs on files and only report new warnings/errors compared to the previous version. This is both a PHP library that can be used manually as well

Small utility library that handles metadata minification and expansion.

composer/metadata-minifier Small utility library that handles metadata minification and expansion.

Small convention based CQRS library for PHP

LiteCQRS for PHP Small naming-convention based CQRS library for PHP (loosely based on LiteCQRS for C#) that relies on the MessageBus, Command, EventSo

Small library providing some functional programming tools for PHP, based on Rambda

Functional library for PHP. Features: set of useful functions helpful in functional programming all functions are automatically curried every array ca

A small PHP library to generate YouTube-like ids from numbers.
A small PHP library to generate YouTube-like ids from numbers.

A small PHP library to generate YouTube-like ids from numbers. Use it when you don't want to expose your database ids to the user.

Releases(0.0.5)
Owner
Ahmad Mustapha
@php enthusiastic, love new ideas. Always learning programming & (space + astronomy) stuffs.
Ahmad Mustapha
This project processes a small database with php all on a web server. This project uses XAMPP to run the web server and the database.

PHP-introduction This project processes a small database with php all on a web server. This project uses XAMPP to run the web server and the database.

Tyler Jacques 1 Jan 6, 2022
The best announcer for PocketMine-MP 4.0 servers, make messages for your users very easily

BroadcastACM The best announcer for PocketMine-MP 4.0 servers, make messages for your users very easily. Make the best announcements for your server w

fernanACM 3 May 30, 2022
A few Fat-Free specific extensions for Tracy Debugger to help debug your code quickly.

Fat-Free Tracy Extensions This is a set of extensions to make working with Fat-Free a little richer. F3 - Analyze all hive variables. Database - Analy

Austin 6 Nov 17, 2022
Quickly and easily preview and test your Magento 2 order confirmation page, without hacks or spending time placing new order each time

Preview Order Confirmation Page for Magento 2 For Magento 2.0.x, 2.1.x, 2.2.x and 2.3.x Styling and testing Magento's order confirmation page can be a

MagePal :: Magento Extensions 71 Aug 12, 2022
Guest to Customer for Magento2 - Quickly and easily convert existing guest checkout customers to registered customers.

Guest to Customer for Magento 2.0 For Magento 2.0.x, 2.1.x, 2.2.x, 2.3.x and 2.4.x In general E-commerce, shoppers do not like to create an account du

MagePal :: Magento Extensions 66 Oct 7, 2022
Spin up a working Statamic instance quickly & easily with Docker

Spin Up Statamic Allows you to create your own self-contained Statamic project complete site config, Antlers/Blade/Twig template files, assets, and de

nystudio107 11 Jun 2, 2023
Easily run code asynchronously

Asynchronous and parallel PHP This library provides a small and easy wrapper around PHP's PCNTL extension. It allows running of different processes in

Spatie 2.3k Jan 7, 2023
Magento 2 Megamenu extension is an indispensable component, and plays the role of website navigation to help customers easily categorize and find information

Mageno 2 Mega Menu (Magicmenu) helps you create neat and smart navigation menus to display the main categories on your website.

https://magepow.com 35 Dec 1, 2022
Composer registry manager that help to easily switch to the composer repository you want

CRM - Composer Registry Manager Composer Registry Manager can help you easily and quickly switch between different composer repositories. 简体中文 Install

Tao 500 Dec 29, 2022
This repository demonstrates exemplary implementation of chat using HTTP and Websocket servers in PHP using Kraken Framework components.

This repository demonstrates exemplary implementation of chat using HTTP and Websocket servers in PHP using Kraken Framework components.

Kraken 48 Aug 11, 2021