Inject\Stack is a minimal base for layered and modular PHP applications. It is a PHP-style port of Ruby's Rack, and because of that it inherits Rack's minimal requirements on the client layers, modules and applications.
For the default usage with a normal MOD_PHP or PHP-FPM installation:
- PHP 5.3 or later
- PCRE Extension (compiled into PHP by default)
- Tokenizer Extension (compiled into PHP by default), used by default
ShowException
middleware to provide syntax-highlighting - PSR-0 Compliant Autoloader, Inject_ClassTools provides one general purpose autoloader as do the Symfony ClassLoader.
If you use any of the other provided adapters and or middleware, additional extensions may be required. For example, the Memcached-session middleware require Memcached.
To install Inject\Stack, you can either download a compressed archive from GitHub or use the InjectFramework PEAR channel:
pear channel-discover injectframework.github.com/pear pear install --alldeps injectfw/InjectStack
If you already have a PSR-0 Compliant autoloader, you do not have to include
--alldeps
in the install command.
A quick hello world example with one of the default middlewares:
<?php // Include and register the autoloader: require 'Inject/ClassTools/Autoloader/Generic.php'; $loader = new \Inject\ClassTools\Autoloader\Generic(); $loader->register(); // Our application $my_endpoint = function($env) { return array(200, array('Content-Type' => 'text/plain'), 'Hello World!'); }; // Let's wrap it in a timer: $stack = new \Inject\Stack\Builder( // List of middleware array( new \Inject\Stack\Middleware\RunTimer() ), $my_endpoint ); $adapter = new \Inject\Stack\Adapter\Generic(); $adapter->run($stack);
Inject\Stack also has support for Mongrel2, which is a high-speed network- and language- agnostic web-server which connects through ZeroMQ directly to running PHP processes. This enables you to get even better performance than the normal PHP web-servers because everything is already running when the request arrives. The downside is that you have to be careful so you don't leak data to other requests or leak memory.
- Mongrel2
- ZeroMQ
- ZeroMQ Extension for PHP
- pcntl Extension, optional, if you want to be able to spawn multiple worker processes directly from PHP.
- No support for
multipart/form-data
yet so no file-transfers can be accepted,application/x-www-form-urlencoded
for normal forms is supported though
Inject\Stack comes with a built-in HTTP server written in PHP which provides high performance as there are no layers in between your code and the client-socket.
- pcntl Extension, required if you want to be able to serve more than one
request concurrently (provides
fork()
so multiple worker processes can share one socket).