PHP App Server (PHAS)
This project emerged from a painful situation...
While I love PHP and code it daily, I come to notice that most of my app's realtime processing is spent on loading classes, thus performing the same job over and over again.
PHAS is designed to be lightweight "application server" that seperates user's request from the actual PHP script that process the request and returns the response. PHAS is not a server per se. Rather it is a seperator between the user's entrance (usually the famous index.php that we all have in our app) and the rest of the application.
How does it work?
In a nutshell, a request that arrive to the "entrace" script is queued and processed later on by a separate "Loop Worker" that listens on the same queue. The "Loop Worker" is basically the rest of your app, that is devided into two sections:
- Bootstrap script - anything from nothing to loading all your classes and functions.
- Loop script - the actual business logic of your app.
Since the Loop Worker is executed on another process or even another machine, it does not share the same global variables as the entrance script. This is currently solved by passing all the global variable from the entrance script to the Loop Worker, thus simulating the same environment and state.
PHAS requires the following:
- PECL gearman extension >= 0.6.0 (please see note for ubuntu users...)
- PHP >=5.3
- Any web server that supports PHP.
Download or clone the package
Edit the server/config/server.config.php according to your needs
Place the "entrance.php" script under a web-server exposed directory.
Run the server-loop.php script from commandline:
php -f /path/to/server/server-loop.php
Use of some native PHP functions and features may work as expected. I'm working on the following issues:
- Using the exit() function may crash the whole process.
- header() function may not work as expected -> use \PHAS\Lib\PHAS::header() instead.
- Using register_shutdown_function may not work as expected.
- Uploading files, Cookies and Sessions are currently expected not to work at all.
Note for Ubuntu Users:
I was having trouble installing the PECL library for gearman on Lucid (10.04). Here's how I eventuall did it:
sudo aptitude install gearman libgearman-dev libgearman2 libevent-dev uuid-dev sudo pecl install channel://pecl.php.net/gearman-0.6.0
At this stage I've been getting an error message like this:
/bin/sed: can't read /usr/lib/libuuid.la: No such file or directory libtool: link: `/usr/lib/libuuid.la' is not a valid libtool archive make: *** [gearman.la] Error 1 ERROR: `make' failed
Thanks to a post by Max Gribov there is a solution. Open /usr/lib/libgearman.la as root, and find a line that says:
dependency_libs=' -L/usr/lib /usr/lib/libuuid.la'
Replace it with:
dependency_libs=' -L/usr/lib /usr/lib-luuid'