Deprecated: Function split() is deprecated in /mnt/home/cn/cn-web/songshu/lib/pages/DisplayBlogArticleList.php on line 36
Articles matching: functions
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-xxxxxxxxx

Popular Articles:


Top Tags:


Recent Comments:

cncool wrote:

GLint zeroOpacity = 0;
[[self openGLContext] setValues:&zeroOpacity forParameter:NSOpenGLCPS...
Posted to: Things I've learned about CoreImage (and Quartz, and OpenGL) in two weeks
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.