我们喜欢在出现问题时打印堆栈跟踪。我们可以使用debug_backtrace轻松地使用PHP。然而问题是,当文件上传或图片上传等问题出现时,我们会获得一个巨大的二进制文件作为跟踪的一部分。像这样:(截断)
#webgloo_ajax_error_handler() called at :0
1175 array (
1176 0 => 256,
1177 1 => 'Image_upload_error',
1178 2 => '/home/rjha/code/github/sc/webgloo/lib/com/indigloo/media/ImageUpload.php',
1179 3 => 95,
1180 4 =>
1181 array (
1182 'prefix' => 'test/2012/04/08/',
1183 'fieldName' => '120444-LM_menu_button.png',
1184 'sBlobData' => '<89>PNG^M
1185 ^Z
1186 ' . "\0" . '' . "\0" . '' . "\0" . '^MIHDR' . "\0" . '' . "\0" . '' . "\0" . 'P' . "\0" . '' . "\0" . '' . "\0" . '^^^H^F' . "\0" . '' . "\0" . '' . "\0" . '»C<99>±' . "\0" . '' . "\0" . '' . "\0" . '^AsRGB' . "\0" . '®Î^\é' . "\0" . '' . "\0" . '' . "\0" . '^FbKGD' . "\0" . 'ÿ' . "\0" . 'ÿ' . "\0" . 'ÿ ½§<93>' . "\0" . '' . "\0" . '' . "\0" . ' pHYs' . "\0" . '' . "\0" . '^K<88>' . "\0" . '' . "\0" . '^K<88>^Aå<8e>)I' . "\0" . '' . "\0" . '' . "\0" . '^GtIME^GÚ^B^R^V 5$=fÞ' . "\0" . '' . "\0" . '^PEIDAThÞÝ<9a>û<8f>]WuÇ?k<9f>sgl<8f>Ç<89>íøAH^P8<89>±<9d>8
理想情况下,我想从我的后面跟踪中删除这样的二进制blob。有没有办法在PHP中可靠地检测二进制字符串?
以下不为我工作。主要是因为我希望解决方案详尽无遗。
这是我目前的回溯发生器
function backtrace() {
fwrite($this->fhandle," ---- __backtrace__ ----- \n" );
$trace = debug_backtrace();
$message = '' ;
foreach ($trace as $i=>$t) {
$message = sprintf("#%d %s%s%s() called at %s:%d \n",
$i,$t['class'], $t['type'],$t['function'],$t['file'],$t['line']);
fwrite($this->fhandle,$message);
$args = $t['args'];
if(!empty($args)) {
//remove blob strings from Argument
Util::unsetInArray($args,array('sBlobData','tBlobData'));
$this->dump($args);
}
}
}