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 This week: 1All time: 6,090 This week: 571Up
Version License PHP version Categories
http-server 0.0.14The PHP License5.4HTTP, PHP 5
Description 

Author

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: 57416 in Russian Federation Russian Federation
Week rank: 103 Up7 in Russian Federation Russian Federation Up
Innovation award
Innovation award
Nominee: 15x

Winner: 2x

Documentation

HttpServer

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

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

Features

  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.

Configuration

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

global:
    listen 80

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

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

global.conf:
    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.

Usage

  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 README.md 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  
 100%
Total:459
This week:1
All time:6,090
This week:571Up