Commit e6ae4af3 authored by luhongguang's avatar luhongguang
parents 51532d3c 807fc4a8
生活圈商户系统工具类库,配合yaf框架使用的基础库
\ No newline at end of file
生活圈商户系统工具类库,配合yaf框架使用的基础库
负责人:崔伟峰
\ No newline at end of file
......@@ -3,7 +3,7 @@
"description": "bp api php_utils",
"type": "library",
"require": {
"php": ">=7.2",
"php": "7.2.*",
"guzzlehttp/guzzle": "6.3",
"mongodb/mongodb": "1.4.3",
"ext-mbstring": "*",
......
......@@ -99,7 +99,7 @@ class MonUtil{
if (empty($db_host)) {
$host = 'unknow';
} else {
$host = str_replace(array(".", ":", "/"),array("_", "_", "-"), $db_host);
$host = str_replace(array(".", ":", "/",','),array("_", "_", "-",'_'), $db_host);
}
//记录请求量
......@@ -107,7 +107,7 @@ class MonUtil{
//耗时打点
if(!empty($request_time) && is_numeric($request_time) && $request_time != -799){
$result = self::timing(($db_name.'.'.$host.$operator), "TotalTime", $request_time);
$result = self::timing(($db_name.'.'.$host.$operator), "TotalTime", $request_time,'s');
}
}
......@@ -219,12 +219,13 @@ class MonUtil{
* @param string $module 子模块名字
* @param string $index 指标
* @param int $value
* @param string $type 单位
* @return mixed
*/
public static function timing($module = 'api', $index = '', $value = 0){
public static function timing($module = 'api', $index = '', $value = 0,$type='ms'){
$result = "";
$send_msg = self::getMsg($module, $index, $value, "ms");
$send_msg = self::getMsg($module, $index, $value, $type);
if($send_msg){
$result = self::base($send_msg);
}
......
......@@ -99,6 +99,21 @@ abstract class MongoBase
);
}
$this->database = $this->client->selectDatabase($this->getDatabaseName());
// xhprof 需要 显示的创建固定大小的集合
$db_collection = [];
if ($this->getDatabaseName() === 'xhprof') {
foreach ($this->database->listCollections() as $item){
$db_collection[] = $item['name'];
}
if (!in_array($this->getCollectionName(), $db_collection, true)) {
//默认创建固定20GB大小的集合
$this->database->createCollection($this->getCollectionName(),['capped' => true,'size' => 21474836480]);
}
}
$this->collection = $this->database->selectCollection($this->getCollectionName(), $this->getCollectionOptions());
}
}
......
......@@ -1459,7 +1459,56 @@ class Medoo
return $result;
}
public function insert($table, $datas, $options = null)
public function selectForUpdateSkipLocked($table, $columns = null, $where = null, $options = null)
{
$map = [];
$result = [];
$column_map = [];
$index = 0;
$column = $columns;
$is_single = (is_string($column) && $column !== '*');
$query = $this->exec($this->selectContext($table, $map, $columns, $where, null, $options) . ' FOR UPDATE SKIP LOCKED ', $map);
$this->columnMap($columns, $column_map, true);
if (!$this->statement)
{
return false;
}
if ($columns === '*')
{
return $query->fetchAll(PDO::FETCH_ASSOC);
}
while ($data = $query->fetch(PDO::FETCH_ASSOC))
{
$current_stack = [];
$this->dataMap($data, $columns, $column_map, $current_stack, true, $result);
}
if ($is_single)
{
$single_result = [];
$result_key = $column_map[ $column ][ 0 ];
foreach ($result as $item)
{
$single_result[] = $item[ $result_key ];
}
return $single_result;
}
return $result;
}
public function insert($table, $datas)
{
$stack = [];
$columns = [];
......
......@@ -37,6 +37,7 @@ use Api\PhpUtils\Log\FileLog;
* @method static MysqlBase select($columns, $where, $options)
* @method static MysqlBase selectMaster($columns, $where, $options)
* @method static MysqlBase selectForUpdate($columns, $where, $options)
* * @method static MysqlBase selectForUpdateSkipLocked($columns, $where, $options)
* @method static MysqlBase getMaster($columns, $where, $options)
* @method static MysqlBase get($columns, $where, $options)
* @method static MysqlBase count($columns, $where)
......@@ -105,6 +106,7 @@ abstract class MysqlBase
"selectMaster", // 或使用/*master*/强制路由,对主从实时性要求较高的场景使用,分布式系统尽量用消息代替查主库等其他方案
"getMaster",
"selectForUpdate",
"selectForUpdateSkipLocked",
"insertDuplicate",
];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment