PHP code example of ahmard / php-server

1. Go to this page and download the library: Download ahmard/php-server library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ahmard / php-server example snippets


use PHPServer\BuiltIn\Server;

Server::create('127.0.0.1', '9900')
    ->setDocumentRoot(__DIR__)
    ->start()
    ->logOutputToConsole();

use PHPServer\BuiltIn\Server;

Server::create('127.0.0.1', '9900')
    ->setRouterScript(__DIR__ . 'public/index.php')
    ->start();

use PHPServer\BuiltIn\Server;

Server::create('127.0.0.1', '9900')
    ->onRequest(fn() => var_dump('Request Received'))
    ->start();

use PHPServer\BuiltIn\Server;

Server::create('127.0.0.1', '9900')
    ->setWorkers(2)
    ->onRequest(fn() => var_dump('Request Received'))
    ->start();

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

composer