PHP Classes

PHP HTTP Server Class: HTTP server that can take virtual host requests

Recommend this page to a friend!
  Info   View files Documentation   View files View files (11)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 459 All time: 6,093 This week: 673Up
Version License PHP version Categories
http-server 0.0.14The PHP License5.4HTTP, PHP 5


This package implements a HTTP server that can take virtual host requests.

It can listen to HTTP requests in a given port of the local machine and handle the requests serving files of the server machine.

The server can handle requests to multiple virtual host names according to definitions read from a separate configuration file.

The request path may be rewritten according to rules defined in the configuration.

Requests that map to files with the .php file name extension will cause the server to execute respective PHP scripts to generate the request response.

It can also cache the responses of requests that match a given path pattern.

Responses can be compressed with the gzip or deflate methods if defined in the configuration.

Innovation Award
PHP Programming Innovation award nominee
March 2015
Number 4

Prize: One copy of the Zend Studio
HTTP servers are very common but they are often separate programs that you need to install to use together with PHP.

Nowadays PHP comes with a built-in HTTP server but it is still very limited.

This class implements a pure PHP HTTP server that implements more complex features like virtual host support, URL rewriting, caching, etc..

Manuel Lemos
Picture of Sergey Vanyushin
  Performance   Level  
Name: Sergey Vanyushin is available for providing paid consulting. Contact Sergey Vanyushin .
Classes: 15 packages by
Country: Russian Federation Russian Federation
Age: 28
All time rank: 57216 in Russian Federation Russian Federation
Week rank: 271 Up16 in Russian Federation Russian Federation Equal
Innovation award
Innovation award
Nominee: 15x

Winner: 2x



This is a http server for PHP completely written in PHP - HttpServer.

> Why do you do this? > - Because I can.


  1. Different hostnames.
  2. GET and POST requests.
  3. PHP files starting (with properly filled _SERVER, _POST, _GET, _COOKIE) and static files downloading.
  4. Forking on any request to avoid delays.
  5. Compression gzip, deflate.


All configuration in file httpserver.configuration. It has blocks and directives inside blocks. For example, this is default configuration:

    listen 80
    document_root C:\Users\User\Documents;
    match *.(png|jpe?g|gif):
        cache 30d;
    replace (.+) /index.php?$1 not_exist;

    document_root C:\Users\User\Documents;
    compress gzip,deflate;

    document_root C:\Users\User\global.conf;

Some special host names:

  1. global - is not a hostname. It is server configuration.
  2. default - is default hostname. If user did not provide host this host will be used.

Server configuration

Inside server configuration following directives available.

  • listen [port].

    > Sets server port to listen on.

Hosts configuration

Inside a block following directives available.

  • document_root [folder]. > Specifies root folder for hostname. Must not end with slash.
  • replace [what] [with that] [flags]. > Allows replace requested path with regular expressions. First argument is an regular expression. Second is a destination path. (Must start with slash). Last arg is flags. not_exist flag changes behavior of replacement: if requested path exist, even if path matches expression, replacement will not be performed.
  • compress [methods]. > Sets available compression methods for response generation. Available: gzip,defalte.
  • match [regex]. > Specifies additional directives for special path(s).
  • cache [cache timeout]. > Tells server to add Cache header in response.


  1. Download and unpack archive
  2. Update with composer (`composer update`)
  3. Run bin/httpserver (`php bin/httpserver`)

  Files folder image Files  
File Role Description
Files folder imagebin (1 file)
Files folder imagesrc (7 files)
Plain text file composer.json Data Auxiliary data
Plain text file httpserver.configuration Data Auxiliary data
Plain text file Doc. Documentation

  Files folder image Files  /  bin  
File Role Description
  Plain text file httpserver Appl. Auxiliary data

  Files folder image Files  /  src  
File Role Description
  Plain text file ConfigurationReader.php Class Class source
  Plain text file HttpException.php Class Class source
  Plain text file HttpServer.php Class Class source
  Plain text file MimeTypeResolver.php Class Class source
  Plain text file SocketReader.php Class Class source
  Plain text file SocketWriter.php Class Class source
  Plain text file WebServer.php Class Class source

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:6,093
This week:673Up