Gettin’ into Git and PHP Process Control

After my last foray with Mercurial, I’m now beginning to work with the distributed source control tool Git. And I like it. Like Hg, it seems it’s used for many projects including the Canvas 3D JS Library C3DL. Like SVN it provides source control, but unlike SVN it is great for its decentralized attitude and being able to run entirely locally if necessary. The learning curve is great too (almost linear) thanks to documentation like kernel.org’s 20 Everyday Git Commands.

Of course Git isn’t enough to get any development done. I’ve been delving into PHP and how to issue commands to OS shells and receive output. Seems there are a lot of different options depending on what you want to do. The basic operations can be used via the system or exec functions, each of which return data back to the calling PHP script for further work. These two differ in two ways:

  • system() allows an array to be filled with all lines of the script output
  • exec() returns the entire output as a string rather than just the first line of output

In situations where the above isn’t enough or when dealing with binary output, the passthru function does the job nicely. This function seems to be the best of the lot: piping the script output directly back to the request stream rather than into PHP (which then goes to the stream) saves a ton of overhead if no additional formatting is required before displaying script output to the user.

As great as these functions are, the entire branch of PHP dealing with process control and program execution require PHP safe mode to be turned off. So it’s easy to use, just some configuration required.

Comments

2 responses to “Gettin’ into Git and PHP Process Control”

  1. Gettin' into Git and PHP-Shell Communication | Syntax Error…

    I found your entry interesting do I’ve added a Trackback to it on my weblog :)…

  2. […] the occurrence of reading week I’ve been a bit behind on my blogging. When I last wrote about PHP Process Control, all seemed fine and dandy. A simple call or two, maybe a foreach loop after to process lines of […]

Leave a Reply

Discover more from Software by Steven

Subscribe now to keep reading and get access to the full archive.

Continue reading