How to convert AGI script to FastAGI script

If you ever need to convert a normal AGI script to be served over the network to one or may Asterisk boxes, you can do as follows:

You can use xinetd for this. From your dialplan on each asterisk box, call agi with a fast agi parameter, substituting your IP address of the fastagi server:

Make sure you have in /etc/services something like:

agi 4573/tcp # FAST AGI entry
On the FastAGI server: In a file called /etc/xinetd.d/agi (make sure /etc/xinetd.conf is loading modules from /etc/xinetd.d/) have a definition which calls your agi script.

# description: agi service for PHP fastagi interaction
service agi
socket_type = stream
user = root
group = nobody
server = /path/to/
wait = no
protocol = tcp
bind =
disable = no
per_source = UNLIMITED
instances = UNLIMITED
cps = 1000 0
In your AGI script, you can now just do as you normally would, by reading STDIN or STDOUT.