PHP Reverse Proxy PRP

Applications and Usage of reverse proxy

Reverse proxy is resolve a request URL to another server machine (or same server with different port) as a remote location. It get the content from the remote location and then return back to the client who request the URL.  The content or the header information can be modified before returning to the client, and the raw content may be stored as cache files or inside a database.  A Reverse proxy can be a building block for other applications, such as 
  • Acting as a load balancing server
  • Acting as a fail-over standby server
  • Cope with a web server
    • acting as a cache server
    • acting as a search engine friendly front end
    • acting as a content filter
  • Portal Front end which served by different type of web-services from different server

Specifications

This project try to create a simple reverse proxy server using PHP, which may be further used to build complex applications. The specifications have been listed as followings: 
  • Written in PHP
  • Support HTTP GET/POST Requests (* Note 1)
  • Support Cookies
  • Support Redirect handling
  • Support Cache Control and able to return HTTP 304 Not modified
  • Customize cache time
  • Allow modification of received content
  • Support path forward
  • Allow target port other than 80

Source Code
 
The source code can be found in the source code page.

 
Demonstration
 
 

 
Reference Reading
 
This class rely on correct setting of Web server for handling File Not Found Error 404. The following articles are related to steps in setting up File Not Found 404 handling pages:
Not only PHP can be served as a development language for Reverse Proxy. I have written Reverse Proxy in Classical ASP as well as Python. The followings are related notes in Python (I will post the ASP version in near future):
 
 
*Note 1: Not all the webservers transfer the POST parameters via the 404 error handling document.