ChipmunkNinja
Ninjas are deadly. Chipmunk Ninjas are just weird.
About this blog
Marc Travels
Marc on Twitter
JustLooking on Twitter

Marc Wandschneider is a professional software developer with well over fifteen years of industry experience (yes, he really is that old). He travels the globe working on interesting projects and gives talks at conferences and trade shows whenever possible.

My Publications:

My book, "Core Web Application Programming with PHP and MySQL" is now available everywhere, including Amazon.com

My "PHP and MySQL LiveLessons" DVD Series has just been published by Prentice-Hall, and can be purchased on Amazon, through Informit, or Safari


ABCHKMPRaRoSTVW
xxxxx-xxx--xxxx

Popular Articles:


Top Tags:


Recent Comments:

macfallen siame wrote:

Marc this is an awesome article that i used for my configuration.I am am delighted that am able to s...
Posted to: Setting up, Configuring, and Using Kannel to send/receive SMS messages

junk yards wrote:

I found the reason 2 days ago (i was too bussy to update you).
The problem was that the UDHL was mis...
Posted to: Setting up, Configuring, and Using Kannel to send/receive SMS messages

Zack wrote:

Thanks! This really fixed my choppy video playback....
Posted to: 1080p MKV playback on Mac OS X (VLC)
Feb 02, 2009 | 03:37:39
PHP Background Process execution in Web Pages
By marcwan

Executing external programs in PHP isn’t a very big surprise – a decent number of articles have been written about the topic, including one I’ve written. However, getting a process to fire off in the background and carry along on its merry way while the web page continues doing its thing is a bit tricker.

You’ll want to use the system shell’s & operator, which means we’ll use the shell_exec function.

If you tried something like:


shell_exec("/path/to/program &");

you’d probably see that the program fired off okay, but that the web page locks up until the program has finished running.

The trick, it seems, is to make sure there is no output from the program. So, be sure to redirect any output to /dev/null, as follows:


shell_exec("/path/to/program > /dev/null &");

And now you can fire off programs willy-nilly. Just be be aware of the security implications of this:

  • Be outrageously careful if you let user input factor into commands (I never do), as they might inject some malicious shell script.
  • Be prepared for possible denial-of-service attacks using this functionality: Are you prepared to handle the case where the web page is requested hundreds or thousands of times?

Happy Programming!

[Read Rest of Article]
Copyright © 2005-2008 Marc Wandschneider All Rights Reserved.