pjdietz/shamserver

Build mini web servers in PHP for testing

v1.0.1 2015-02-10 22:19 UTC

This package is auto-updated.

Last update: 2024-04-12 05:30:51 UTC


README

Build Status

ShamServer allows you to build mini web servers for testing.

It uses PHP's built in web server feature to spawn a separate process that listens for incoming requests and responds to them using the router script you provide.

use pjdietz\ShamServer\ShamServer;

$host = "localhost";
$port = 8080;
$router = "/path/to/my/router.php";

// Start up a testing web server.
$server = new ShamServer($host, $port, $router);

// A server is now listening at http://localhost:8080

// Shut down the web server.
$server->stop();

StringShamServer

You can also use StringShamServer to create the router file for you. When you instantiate, pass a string containing the entirety of a PHP router script. The instance will write this to a temporary file, use it for the server, and them remove it.

// Create a server that always responds with a 401 status code.
$host = "localhost";
$port = 8080;
$router = "<?php http_response_code(401);";
$server = new StringShamServer($host, $port, $router);

Routers

For more information on how to write router scripts, see the PHP Manual.

Install

Add an entry for "pjdietz/shamserver" to your composer.json file's require or require-dev section.

Copyright and License

Copyright © 2014 by PJ Dietz Licensed under the MIT license