So Phil Sturgeon tweeted that he was looking for a Mock HTTP server with some simple functionality. This sounded like a fun and useful project and it seemed that there was nothing like it on Packagist. So I implemented it =)
Github repo: https://github.com/phpixie/illusion
Packagist: https://packagist.org/packages/phpixie/illusion
Usage is as simple as can be:
1
2
3
4
5
6
7
8
9
10
11
12
13
//Set up client
$illusion = \PHPixie\Illusion::start($port = 4747);
//Set up a route and response and get a URL
$url = $illusion->route('/pixie/fairy', 'Trixie');
//And now:
echo file_get_contents($url); // 'Trixie'
//Also with HTTP method and headers support
$headers = array('Content-Type: text/plain');
$url = $illusion->route('/pixie', 'PHPixie', 'GET', $headers);
It’s simple like that, and it also helped me brush up my socketing skills ^__^
P.S. use this composer.json to try it out:
1
2
3
4
5
{
"require":{
"phpixie/illusion": "dev-master"
}
}