Skip to content

Instantly share code, notes, and snippets.

@sofish
Created December 21, 2012 09:28
Show Gist options
  • Save sofish/4351721 to your computer and use it in GitHub Desktop.
Save sofish/4351721 to your computer and use it in GitHub Desktop.
stacktrace store
<?php
$url = new Url();
$page = $url->post('page');
if(!$page) return;
class ErrorTrace extends MongoData {
// MongoData 中没有,区别 http://stackoverflow.com/a/7958954
public function findOne($obj) {
return $this->connection->findOne($obj);
}
};
$store = new ErrorTrace();
$fields = array(
'url' => $url->post('url'),
'message' => $url->post('message'),
'line' => $url->post('line'),
'ua' => $url->post('ua'),
);
$index = array('page' => $page);
$hash = md5(json_encode($fields));
// 不重复记录一个错误,所有错误记录在同一个 URL 下
if($field = $store->findOne($index)) {
if(isset($field[$hash])) return;
return $store->setAttr(new Query('page', $page), $hash, $fields);
}
$store->page = $page;
$store->$hash = $fields;
$store->save();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment