Wednesday, 28 September 2011

PHP - Exec, PassThru & System calls

When you're working with PHP, hosted by Apache, if you are using the calls "exec", "passthru" or "system" to call into other applications you can miss changes in those apps, unless you change the PHP script before accessing the page again.

So, I have my browser pointed to my PHP page as "" and in that PHP page script I have a call to "exec /usr/bin/myapplication" which is a program I've written in C++.

Now, if I change the application in C++ and recompile it, then refresh the browser I can fail to see any change, the Apache Server/PHP engine keeps the last version run cached.  Great for speeding up your server, but a pain in the bum when you're trying to debug that C++ application through the web-browser interface.

The best solution to making sure your changes to the C++ show up appears to be to simple put an edit into the PHP file and save it again.

Note; Not even copying the PHP file into /var/www again makes a difference, the file itself has to change, if only by adding a space and then removing it again.

This edit then makes the Apache/PHP engine drop the cached version of the C++ Application and run it from scratch.  This same problem must happen if you do anything to change any application you are calling with the above PHP commands.

No comments:

Post a Comment