outln(__FILE__." line: ".__LINE__); // // In a Unix shell, tail -f ggg-trace.out and watch what your php is doing. // // Print variables (nested arrays are printed recursively) like this: // $ggg_tracer->out('$arrayName = '); $ggg_tracer->outvar($arrayName); // // BE SURE TO DELETE OR COMMENT OUT ALL REFERENCES TO THIS BEFORE RELEASING // YOUR PHP! // /** * */ class GggTrace { public $fp; /** * @param string $nameStr */ public function __construct($nameStr = 'ggg-trace.out') { register_shutdown_function([&$this, 'gggTraceShutdown']); // the & is important $this->fp = fopen($nameStr, 'a'); fwrite($this->fp, "\n"); // e.g. 20031231 17:00:20 fwrite($this->fp, '*' . date('Ymd G:i:s') . "*Starting*****************************************************\n"); // print date("Ymd G:i:s
",time()); // e.g. 20031231 17:00:20 } /** * @param string $outStr */ public function out($outStr = '') { fwrite($this->fp, "$outStr"); } /** * @param string $outStr */ public function outln($outStr = '') { fwrite($this->fp, "$outStr\n"); } /** * @param $var * @param int $indent */ public function outvar($var, $indent = 0) { if ($indent > 8) { fwrite($this->fp, "Too many levels of recursion! \n"); return; } $spaces = sprintf('%' . $indent . 's', ''); fwrite($this->fp, $spaces . $var . "\n"); if (is_array($var)) { $indent++; $spaces = sprintf('%' . $indent . 's', ''); foreach ($var as $key => $val) { if ($key === 'GLOBALS' && is_array($val)) { // In case we are called with $ggg_tracer->outvar($GLOBALS); // and we don't check here, we get an infinite recursion. // If another array has an element called GLOBALS, oh well. fwrite($this->fp, "ggg-trace.php, line 62: Found GLOBALS array, not recursing. \n"); } elseif (is_array($val)) { $this->out($spaces . "$key = "); $this->outvar($val, $indent); } else { fwrite($this->fp, $spaces . $key . '=>' . $val . "\n"); } } } } public function gggTraceShutdown() { fwrite($this->fp, '*' . date('Ymd G:i:s') . "*Finishing****************************************************\n"); fclose($this->fp); } } $ggg_traceFiles = new GggTrace('ggg-traceFiles.out'); $ggg_traceFiles->outln(__FILE__); $ggg_tracer = new GggTrace(); // $ggg_tracer->outln("Tracer initialized in ggg-trace.php...");