
1. Introduction
---------------

spawn-fcgi is used to spawn fcgi-process directly without the help of a
webserver or the programm itself. It was written as the option "-b" of php
4.2.x and above was broken. 

In general it gives you more controll over the to-be-spawned process as you
can create a spawn the process in a chroot() environment, set your own
envirnoment and you can execute the fcgi-process in its own user-context.

2. Using spawn-fcgi
-------------------

$ ./spawn-fcgi
spawn-fcgi-1.0.0 - spawns fastcgi processes
usage:
 -f <fcgiapp> filename of the config-file
 -p <port>    bind to tcp-port
 -C <childs>  (PHP only) numbers of childs to spawn (default 5)
 -v           show version
 -h           show this help
(root only)
 -c <dir>     chroot to directory
 -u <user>    change to user-id
 -g <group>   change to group-id
 
 
Example:

$ /usr/bin/spawn-fcgi -f /usr/bin/php -p 1026


2.1. Using spawn-fcgi the right way
-----------------------------------

spawn-fcgi takes the environment of the calling process (the shell) and add
PHP_CHILDRENS to the environment. 

In general it is not a good idea to expose the envirnment of the calling
process to the fcgi-programm. To clean out the environment you should use a
wrapper around spawn-fcgi like:

---------------------
#!/bin/bash

SPAWNFCGI="/usr/bin/spawn-fcgi"
FCGIPORT="1026"
FCGIPROGRAM="/usr/bin/php"

EX="$SPAWNFCGI -p $FCGIPORT -f $FCGIPROGRAM"

# allowed environment variables sperated by spaces
ALLOWED_ENV="ORACLE_HOME"

# copy the allowed environment variables
E=

for i in $ALLOWED_ENV; do
  E="$E $i=${!i}"
done
  
# clean environment and set up a new one
/usr/bin/env - \
$E \
$EX

---------------------

2.2. Using a chroot
-------------------

The chroot-support is only available if spawn-fcgi is called by root.

$ /usr/bin/spawn-fcgi -f /usr/bin/php -p 1026 \
  -c /home/www/servers/ -u php -g wwwrun
  
