hub20xx/php-local-server

A class to manage PHP's built-in server

v1.1.5 2017-03-13 10:58 UTC

This package is not auto-updated.

Last update: 2024-04-13 17:35:49 UTC


README

Build Status

You're on linux and you want a simple way to start and stop a local server.

Install

Via Composer

$ composer require hub20xxx/php-local-server

Usage

require __DIR__ . '/vendor/autoload.php';

$docroot = __DIR__ . '/www';

// by default the server is running on 127.0.0.1:1111
$server = new PhpLocalServer\Server($docroot);

// you can specify the address and port
// in the constructor
$address = '127.0.0.2';
$port = '1234';
$server = new Server($docroot, $address, $port);

// or using the setters
$server = new Server($docroot);
$server->setAddress($address);
$server->setPort($port);

// setting environment variables
$server->setEnvironmentVariable('ENV', 'testing');
$server->setEnvironmentVariable('FOO', 'bar');

// starting the server
$server->start();

// using the server

// stopping the server
$server->stop();

// $server->stop() is called in the destructor in case you omit to stop the server

Testing

$ phpunit

License

MIT

Credits / Thanks

This package was inpired by this blog post

Many thanks :)

Contributing

If you'd like to contribute, please use Github (issues, pull requests etc).