Execute a background task in PHP

There are a ton of ways of running a task in the background (like a daemon, etc) from PHP but this must surely be the slickest –

sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, $outputfile, $pidfile)

This will execute $cmd, writing it’s output to $outputfile, and saving it’s pid in $pidfile. The last two can be /dev/null of course.