There are many ways to implement flash remoting such as AMFPHP, PHPObject, Flap and ColdFusion Component, but in my case, I like AMFPHP best to carry on it. However, when I am working on the development of RIAs depended on Flash Remoting, I sometimes get stuck in figuring out what kinds of errors are happenning in php programming. Because flash remoting is sort of a black box, which we can't find errors very easily, and other debbuggers such as NetConnection Debugger are very unstable, I usually use the simple class (FileDumper) for debugging errors in amfphp. These days, when I make RIAs, I use this class for simple debugging, and I found it time-effective and efficient.
The source of FileDumper class is as follows.
<?php// writeDumper class
class FileDumper {
var $_filename;
var $_dump;
// set the file name
function setFilename($filename) {
$this->_filename = $filename;
return $this;
}
// set the dump content
function setContent($dump) {
$this->_dump = $dump;
}
// write the dump content
function writeDump($data = null) {
if ($data) {
$this->setContent($data);
}
if(!function_exists('file_put_contents')) {
$fp = fopen($this->_filename, 'a+');
flock($fp, LOCK_EX);
ob_start();
var_dump($this->_dump);
$res = fwrite($fp, ob_get_contents());
ob_end_clean();
fflush($fp);
flock($fp, LOCK_UN);
fclose($fp);
} else {
ob_start();
var_dump($this->_dump);
$res = file_put_contents($this->_filename, ob_get_contents());
ob_end_clean();
}
}
}
To use this class in AMFPHP,
<?php $error = 'error'; $fd = new FileDumper(); $obj = $fd->setFilename('full path/dump.txt'); $obj->writeDump($error); ?>
After start using this class to debug, it became very easy for me to find what errors are in my local environment. It is a little annoying for people who are unable to use vi to open the file of debugging, but it is way better for me to use it than to fight with the errors that I can't see.