It is a hassle to use PHP for command-line programs, since it is originally meant for webscripts only, but they are working on making it easier. Since 4.2.0 it has been possible to compile a cli-version binary but it has been experimental. From 4.3.0 (development version) it is no longer experimental and is always built.
I have tried this CLI binary for 4.2.2 once or twice and it seems to work.
With this implicit_flush variable of php.ini is overridden so that nothing is buffered. The max execution time is set to infinite, html_errors is set to false and the $argc and $argv variables are set with the arguments sent to the program. In addition to this, STDIN, STDOUT and STDERR are always opened.
More information can be found
here.