/ Published in: PHP
Usage:
watch -d -n 1 'php watch.php -f test.php'
Where watch.php is the name of this PHP file where you save this snippet and test.php is the PHP file you are editing. This will allow you to watch the output of the file while you edit it.
Aptana/Eclipse has a terminal window view, that you can use to watch your code executed live with this snippet.
Expand |
Embed | Plain Text
<?php /** * Execute a PHP file given by the -f option only if it has changed * @author [email protected] * @link http://www.fijiwebdesign.com/ */ // eg: php watch.php -f test.php // will have $file = test.php $file = $opts['f']; } // should we execute file $exec = false; // our compare for this file changes // our file where output is saved $output_file = $meta_file . '-out'; // current hash of file contents // old hash of file contents // if the hashes do not match, a change occurred in content if ($old_hash != $curr_hash) { // execute file since it changed $exec = true; } } else { // execute file since first run $exec = true; } // save the current file content hash to our meta file file_put_contents($meta_file, $curr_hash); // our ouput buffer $output = ''; // execute our file if changed if ($exec) { require($file); // save output for display later also file_put_contents($output_file, $output); } else { } } // display our output echo $output;
You need to login to post a comment.
