PHP’s exec Command

Posted by on October 31, 2011 in Operating Systems, PHP, Programming | 0 comments

Some things to note about PHP’s shell execution.

The syntax:

exec(“command php”, $array=optional);

So the first thing to note is that if you do not include the optional array, which is a pass by reference variable, that the command will not wait until it’s done executing before moving on in the PHP code. If you do include the array, it will put the output of the command into the array, unless in your command you route the output to another spot, like a text file.

Also note that if you have multiple exec’s in the same PHP script, it will append the results onto the array you pass it. You need to physically get reset the array to empty before you call your exec.

exec is a great way to do operating system calls from PHP. Alot of times there are easier ways to do things with native OS functions than to use the PHP scripts.

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment

Your email address will not be published. Required fields are marked *