PHPackages                             pjdietz/shamserver - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. pjdietz/shamserver

ActiveLibrary[HTTP &amp; Networking](/categories/http)

pjdietz/shamserver
==================

Build mini web servers in PHP for testing

v1.0.1(11y ago)02521MITPHPPHP &gt;=5.4.0

Since Jul 26Pushed 11y ago1 watchersCompare

[ Source](https://github.com/pjdietz/ShamServer)[ Packagist](https://packagist.org/packages/pjdietz/shamserver)[ Docs](https://github.com/pjdietz/ShamServer)[ RSS](/packages/pjdietz-shamserver/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (3)Used By (0)

ShamServer
==========

[](#shamserver)

[![Build Status](https://camo.githubusercontent.com/57cda7b369380b01328673c86420ca57f9f0febe6c716368c13fc758bff88fb8/68747470733a2f2f7472617669732d63692e6f72672f706a646965747a2f5368616d5365727665722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/pjdietz/ShamServer)

ShamServer allows you to build mini web servers for testing.

It uses [PHP's built in web server feature](http://php.net/manual/en/features.commandline.webserver.php) 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
----------------

[](#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 = "
