Do you remember long ago our “start of regime” trying to show you, as users, the code differences as we go through a project when we presented the Linux diff Primer Tutorial starring the Linux (or unix) diff command?
Well, today, we build a layer (“onions of the 4th dimension” methinks) on top of it, that brings together PHP (some for the first time) …
… and as its (command) name might suggest “passthru” can do just that in your PHP. The PHP is writing out HTML (or other types of data via an appropriate header command) and at any time whatever you get as output from an operating system command line call of the command you have as passthru‘s parameter becomes part of that HTML (or other data), unlike exec‘s outputting of just the last line as a return or placed in an array and shell_exec‘s outputting of all the output lines as a return (array) or placed into an array.
The “onions of the 4th dimension” side to this is that via “passthru”‘s “curl” (verbalised) command parameter we contain the gist of any one diff report run of the past, and all these can be being processed by our new live run‘s prediff.php PHP code’s use of glob to harness …
- “filespec” (to the user is like a “urlspec” with a “filled in” and “readonly” website document root “URL” (of the webpage’s (web server) domain) as a prefix to a variable “subdirectoryfilespec” if you will … (and hope you see our concerns to really restrict what you can run a report on here) … along with
- file modified date since (optionally set by user)
- file modified date before (optionally set by user)
… presented in an HTML form method=POST action=./prediff.php (ie. here’s looking at you, kid).
We don’t show much about the underlying diff.php (very hard working duck … “this time with a curl, rather than trapped in an iframe” … tee, hee), but it changed to cater for what the supervisor HTML presentation would ask of its underling. No worries here, as long as the testing works for diff.php acting the same way it ever did unsupervised … which is “top priority” by the way.
Previous relevant Linux diff Primer Tutorial is shown below.
The Linux (or unix) command diff is a powerful command line tool that does file comparisons at the command line of a Linux (or unix) operating system. When you are coding this type of tool can be very important. You may not like to do such tasks in the command line, and have to say that a GUI (on Windows UltraEdit (text editor) is brilliant, on Mac think TextWrangler does a good job here) type of comparison works better for me, and Source Control techniques work well for many programmers, but GUI doesn’t always gel with integration, and want to show you today how the Linux diff can be incorporated into your PHP code. In saying this, am recommending extreme care with this, as its misuse can have bad implications for the whole website to be exposed to the outside world. Balancing this up against wanting to have a tool for users of this web blog to (have a more automated way to) be able to see the comparisons of files of changing code, as in yesterday’s tutorial, have decided to show the workings of this, in the rudimentary way it is used here. At the other end of diff, its output can be used by patch to make diff an even more powerful tool, and there are links about all this below.
Some good background reading here would be:
- diff (Linux or unix diff command)
- exec (as interface to use with PHP on the web)
- patch (as a way to use diff output as input to Linux or unix patch command)
So … why does the picture for this tutorial not show a Linux command line screen? Well, today we show you the power of the combination of Linux commands and the PHP way to access these commands (in our case with diff.php … the PHP exec() method). The follow up issue that tomorrow’s tutorial will address is the idea of an Apache web server configuration allowing a file “extension” to be mapped to a URL arrangement of your choosing … will save the idea here for that future tutorial, as this topic area is very big and needs the user to step back and think about, a lot, before considering.
Specifically, in diff.php (of the picture) it has a line of code …
exec(“diff ” . dirname(__FILE__) . “/one.one ” . dirname(__FILE__) . “/two.two > ” . dirname(__FILE__) . “/huh.huh”);
… to bring (Linux) diff results to the web for file comparison purposes … clicking on the picture of the tutorial shows a picture showing the link that got clicked to create the webpage of the front picture. This all sprung from yesterday’s PHP/Javascript/HTML Geographicals By Placename Tutorial. By the way, am not showing all the code of diff.php today, and am sorry about that, but rest assured the line of code above is its crucial part.
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.