PHP Classes
elePHPant
Icontem

PHP Multi-Server: HTTP Server written in pure PHP

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Info   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2011-07-08 (4 years ago) RSS 2.0 feedStarStarStarStar 66%Total: 1,328 This week: 1All time: 2,753 This week: 1,103Up
Version License PHP version Categories  
php-multi-server 1.0GNU Lesser Genera...5.1Networking, HTTP, PHP 5, Unix
Description Author  

This class implements an HTTP server written in pure PHP.

It starts a daemon that listen for connections and handles HTTP GET and HEAD requests.

The class can start children processes to handle multiple requests in parallel.

The requests may serve static files inside the document root directory. The class supports checking for modified files and return the appropriate responses for unchanged files.

Recommendations  

Create PHP desktop application
I would like to create PHP project for desktop computers

Picture of Artur Graniszewski
Name: Artur Graniszewski is available for providing paid consulting. Contact Artur Graniszewski .
Classes: 13 packages by
Country: Poland Poland
Age: 33
All time rank: 3205 in Poland Poland
Week rank: 219 Up6 in Poland Poland Down
Innovation award
Innovation award
Nominee: 7x

Winner: 1x

Details provided by the author  
phpMultiServer 1.0.0 lite

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

Thanks to various optimizations, this server is able to achieve ~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 Server with mod_php 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 as in the original software. 

This little demo is a proof-of-concept and an educational example of network/inter-process programming in PHP.

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.
* 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 HTTPD functionality)


REQUIREMENTS
---------------
This software works only in CLI (Command Line Interpreter) mode. 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.

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

ServerConfig::$documentRoot - stores the local path to the webpage directory (ie /home/users/drupal/public_html).

ServerConfig::$serverRoot - stores the local path to the HTTP server directory (ie /root/server).

ServerConfig::$socketAddress - stores the IP address of the server, which will be used for communication between server and the HTTP clients (ie 127.0.0.1 for localhost or 0.0.0.0 to listen on all available IP's)

ServerConfig::$socketPort - stores the port number on which the HTTP server will listen for incoming connections (ie port 80).

ServerConfig::$logFile - stores the path of log file used by this HTTP server.

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
----------------
Unpack the class, enter the class home directory and type below 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


PRO 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)
  Files folder image Files  
File Role Description
Plain text file server.php Class Main class
Accessible without login Plain text file readme.txt Doc. class documentation
Accessible without login Plain text file license.txt Lic. LGPL License
Accessible without login Plain text file benchmarks.txt Data Benchmark tests
Accessible without login Plain text file example.txt Data Example file

 Version Control Unique User Downloads Download Rankings  
 0%Total:1,328All time:2,753
 This week:1This week:1,103Up
 User Ratings  
 
 All time
Utility:93%StarStarStarStarStar
Consistency:100%StarStarStarStarStarStar
Documentation:100%StarStarStarStarStarStar
Examples:-
Tests:-
Videos:-
Overall:66%StarStarStarStar
Rank:408