Created
December 21, 2012 09:28
-
-
Save sofish/4351721 to your computer and use it in GitHub Desktop.
stacktrace store
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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