Recommend this page to a friend! |
Download |
Info | Example | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not yet rated by the users | Total: 54 | All time: 10,612 This week: 206 |
Version | License | PHP version | Categories | |||
php-server 1.0.0 | Shareware | 5 | HTTP, PHP 5, Libraries |
Description | Author | |||||||||||||||||||||||
This package can run applications with different types of the Web server. |
|
<?php |
A small library to help run PHP servers easily and quickly.
composer require ahmard/php-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 (31) |
File | Role | Description | ||
---|---|---|---|---|
bin (3 files) | ||||
src (11 files, 3 directories) | ||||
composer.json | Data | Auxiliary data | ||
phpstan.neon | Data | Auxiliary data | ||
README.md | Doc. | Documentation | ||
requests.http | Data | Auxiliary data | ||
test-builtin.php | Example | Example script | ||
test-react.php | Example | Example script | ||
test-swoole.php | Example | Example script |
Files (31) | / | bin |
File | Role | Description |
---|---|---|
built-in.php | Example | Example script |
react.php | Example | Example script |
swoole.php | Example | Example script |
Files (31) | / | src |
File | Role | Description | ||
---|---|---|---|---|
BuiltIn (1 file) | ||||
React (1 file) | ||||
Swoole (3 files, 1 directory) | ||||
AbstractServer.php | Class | Class source | ||
Env.php | Class | Class source | ||
functions.php | Aux. | Auxiliary script | ||
Kernel.php | Class | Class source | ||
RunningServer.php | Class | Class source | ||
ServerCommand.php | Class | Class source | ||
ServerInfo.php | Class | Class source | ||
ServerInterface.php | Class | Class source | ||
ServerProcess.php | Class | Class source | ||
StartedServerInterface.php | Class | Class source | ||
Terminal.php | Class | Class source |
Files (31) | / | src | / | Swoole |
File | Role | Description | ||
---|---|---|---|---|
Http (4 files, 1 directory) | ||||
Console.php | Class | Class source | ||
Kernel.php | Class | Class source | ||
Server.php | Class | Class source |
Files (31) | / | src | / | Swoole | / | Http |
File | Role | Description | ||
---|---|---|---|---|
Middlewares (1 file) | ||||
Middleware.php | Class | Class source | ||
Request.php | Class | Class source | ||
RequestMiddleware.php | Class | Class source | ||
Response.php | Class | Class source |
Files (31) | / | src | / | Swoole | / | Http | / | Middlewares |
File | Role | Description |
---|---|---|
MiddlewareInterface.php | Class | Class source |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.