koriym / php-server
Requires
- php: ^8.0
- symfony/process: ^5.4
Requires (Dev)
- ext-curl: *
- bamarni/composer-bin-plugin: ^1.8
- phpunit/phpunit: ^9.6.19
- psalm/plugin-phpunit: ^0.18.4
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-19 09:47:35 UTC
README
Simple PHP built-in server utility for testing
Do you ever need to test using a http server? This utility will fast launch a built-in PHP server just when you need it.
Installation
composer require koriym/php-server
Usage
$server = new PhpServer('127.0.0.1:8080', 'path/to/index.php'); $server->start(); // your http test here $server->stop();
You can also specify a public web directory.
$server = new PhpServer('127.0.0.1:8080', 'path/to/public');
Server output (access log, error_log(), notices) is written to a log file instead of a pipe, so a chatty
application never blocks the server. A temporary file is used by default and removed when the process ends;
pass your own path to keep the output.
$server = new PhpServer('127.0.0.1:8080', 'path/to/public', logFile: sys_get_temp_dir() . '/php-server.log'); $server->start(); echo $server->getLogFile();
start() waits until the port accepts connections. It throws a RuntimeException when the port is already in
use, and when the server exits during start-up, where the message ends with the tail of the log file.
stop() is safe to call more than once and throws only when the server died before being stopped.