Improved PHP exec() Function

When using PHP’s exec function, it isn’t possible to get stdout which makes troubleshooting difficult. Thanks to Mark on StackOverflow, this improved version of exec(), using proc_open(), lets you capture not just the output but also the errors in a separate variables.

This came in useful for me when setting up a simple InterMapper probe which counts files created within a certain time period. It was failing, giving different results from when I would run the command in the Terminal. It was a permissions error, and the function above helped me to verify this.

 

Leave a Reply

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