Executing scripts/programs fro …

Executing scripts/programs from a web page can be troublesome and fraught with security issues. Executing long running scripts is troublesome as well as the webpage appears to never stop loading! Here’s how to get around it in PHP.
Usually I use exec() or system() to run external script but the script I wanted to run this time wasn’t supposed to exit! I had to find another way. I used popen():

$cmd = "command &"
$fp = popen ( $cmd, "r");
sleep( 1 );
pclose($fp);

That will run the command, wait 1 second and then close the pipe to the command. A message on the popen() manual page above warns that file descriptors may be left open and the Apache process may not respond to further queries but I haven’t tested that.

Leave a Reply

%d bloggers like this:

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close