phpMultiServer, a high-performance HTTP server written in pure PHP

This is a sample, high-performance HTTP server written in pure PHP.

Thanks to various optimizations, this server is able to handle more than 800 HTTP requests/second on a dual core laptop (Core 2 Duo 1.6Ghz).

This in turn allows you to create highly efficient PHP scripts with low response times (less than 1ms latency between sending request to launching PHP script).

In result this software is sometimes faster than the Apache HTTP Server (which is written in highly efficient C language).


Please note: this is just a ‘lite’, stripped version of the much larger solution, so the source code is not as flexible/complete as in the original software.

This little demo is rather a proof-of-concept. I post this software for educational puproses in order to demonstrate the network/inter-process programming in PHP.

Server features

* Supports GET/HEAD HTTP requests.
* Highly efficient PHP code (up to 4 concurrent HTTP requests/1 CPU core ratio)
* Basic security mechanisms (ie. server drops root privileges after launch, uses realpath() to protect itself against path traversal attacks)
* Uses multicore processing (no CPU/memory limits)
* Works as a daemon or CLI application.
* Provides garbage collector.
* Supports customizable index file names.
* Supports If-Modified-Since header and ‘403 Not Modified‘ responses.
* Supports some basic MIME types (you can add your own)
* Provides configurable preforking mechanism (mimicking Apache HTTP Server functionality)


This software works only in CLI (Command Line Interpreter) mode on Linux/Unix OS’s. It needs the root privileges to launch properly (after start phpMultiServer drops it’s root privileges and switches it’s effective UID to the standard, configurable user).

Required PHP extensions: POSIX, Semaphore, PCNTL.

Where to download

You can download phpMultiServer from this link (file size: 14KB).

Basic configuration

Server settings are stored in server.php file, in a ServerConfig class. For starters: try to change these settings:

  1. ServerConfig::$documentRoot - stores the local path to the webpage directory (ie /home/users/drupal/public_html).
  2. ServerConfig::$serverRoot – stores the local path to the HTTP server directory (ie /root/server).
  3. ServerConfig::$socketAddress – stores the IP address of the server, which will be used for communication between server and the HTTP clients (ie to listen on all available IP’s)
  4. ServerConfig::$socketPort - stores the port number on which the HTTP server will listen for incoming connections (ie port 80).
  5. ServerConfig::$logFile – stores the path of log file used by this HTTP server.
  6. ServerConfig::$user, ServerConfig::$group – stores UID/GID of the unprivileged user, which will be used by the HTTP server (ie nobody/nobody)

There is a bunch of other low level options too (documented in the sourcecode).

How to launch the server

Unpack the PHP files, go into server’s home directory and type following commands using the root privileges:
php -f server.php start – starts the HTTP server (daemon mode)
php -f server.php stop – stops the HTTP server
php -f server.php debug – launches HTTP server in debug mode (press Ctrl+C to kill the application)

Professional version

Professional version includes additional functionalities like:
* Gzip/deflate compression, POST requests and CGI support in HTTP wrapper.
* Flexible source code (support for plugins and various protocols)
* Supports various communication protocols (FTP/MySQL connection pooler/PDO proxy/POP3/IMAP/SMTP,SQLite over network)
* Even more efficient PHP code.
* SOAP server mode (with WSDL generator)

2 Responses to “phpMultiServer, a high-performance HTTP server written in pure PHP”

  1. Alfredo says:

    Please where can i get more information about teu professional version of phpMultiServer ? is ther a link i can visit ?

    thanks very much.

  2. Artur Graniszewski says:


    professional version is not yet open sourced. Fortunately I’ll post more advanced versions of phpMultiServer in near future.

Leave a Reply