首页
Search
1
解决 docker run 报错 oci runtime error
49,335 阅读
2
WebStorm2025最新激活码
27,568 阅读
3
互点群、互助群、微信互助群
22,731 阅读
4
常用正则表达式
21,540 阅读
5
罗技鼠标logic g102驱动程序lghub_installer百度云下载windows LIGHTSYNC
19,320 阅读
自习室
CODER
课程
SEO
学习视频
手册资料
呆萌
工具软件
运维
DBA
互通有无
资源
微信群
激活工具
搞钱日记
养生记
包罗万象
登录
Search
标签搜索
DeepSeek
学习指北
Prompt
提示词
Loong
累计撰写
179
篇文章
累计收到
0
条评论
首页
栏目
自习室
CODER
课程
SEO
学习视频
手册资料
呆萌
工具软件
运维
DBA
互通有无
资源
微信群
激活工具
搞钱日记
养生记
包罗万象
页面
搜索到
36
篇与
的结果
2019-07-09
高性能网站架构方案
高性能网站架构方案,用以优化网站响应时间,实现大型网站技术架构方案。无论是电子商务或者其他网站且可使用。一、优化网站响应时间的架构方案: 网站能不能留的住用户,一方面是看内容,另一方面是看响应时间。通常有以下几个方式来降低网站响应时间: 1、减少HTTP请求。包括合并css和javascript。减少图片数量,比如利用css的偏移技术来在一个图片中选择不同的位置内容。利用浏览器的Cache功能,我们可以在头中声明是否被浏览器缓存。 2、动态内容静态化。比如永久生成HTML文件。生成静态文件并设定生存时间,到期后查询新的动态内容进行替换。 3、优化数据库。数据库的性能对于项目整体性能中是重中之重。设计良好的Mysql比乱糟糟的Mysql性能高出N个数量级,更别论再引入NOSQL了,比如Redis,MongoDB。 4、使用负载均衡。将请求合理的分发到更多服务器。 5、使用缓存。把花费时间和资源成本高昂的计算结果取出缓存起来,避免重复计算。比如在Mysql前面挡一层Memcached。比如生成一个文件,使用的时候include进来。再比如PHP中的OPCACHE等。二、压力测试的架构方案: 吞吐率是指单位时间内处理的请求数,单位reqs/s。最大吞吐率是指单位时间内能够处理的最大请求出。模拟足够多的人数和并发请求来测试最大吞吐率的方法叫做压力测试。比如Apache自带的ab(Apache Bench)。ab的参数很多,常用的有请求数(-n),并发用户数(-c),超时时间(-t),长连接(-k),附件一个Cookie(-c name=value)$ab -c 10 -n 1000 http://localhost/三、长连接的架构方案: 每次请求都需要TCP的三次握手,握手完比表示连接正式联通,之后再发送数据。那么,把N个请求,就需要3N次握手,传递N次数据,得到N次响应,总共5N。如果把N个请求合成一个请求,就是3次握手,1次传递数据,1次返回响应,共5次。但是,有时候我们需要上一次响应的返回结果来发送新一轮的请求,在这个时候,合并请求并不好实现,这就需要长连接。使用起来很简单,在头中包含如下:Connection: Keep-Alive 客户端和服务器端都可以设置长连接的最大时间,当两者不统一时以小的一方为准。开启长连接后进行压力测试:$ab -c 10 -n 1000 http://localhost/ 发现提升不止三五倍。本机是提升了8倍的性能。四、提高Mysql的响应速度的架构方案: Handlerocker是日本的一位架构师开发。Mysql的一种插件。Handlerocker实现了绕过Mysql的SQL解析层。在Mysql5.1以上版本可以使用,详情可以查看Mysql手册。这里就不在阐述。五、Mysql主从复制的架构方案: 在分布式部署中,1台主库,N台从库。主库只写,从库只查。主库从库数据需要实现统一,这就是主从复制。优点是: 1、从库备份时,主库可以继续处理更新。 2、优化响应时间。 3、增加健壮性。主库挂了可以切换到从库作为备份。 主从复制的实现过程有三步,1个在主库,2个在从库: 1、主库服务器将用户对数据库更新的操作以二进制格式保存到Binary Log日志文件。然后Binlog Dump线程将Binary Log日志文件传输给从库服务器。 2、从库服务器通过一个I/O线程将主库服务器的Binary Log日志文件中的更新操作复制到一个叫做Relay Log中的中继日志文件中。 3、从库服务器通过另一个SQL线程Relay Log中继日志文件中的操作依次在本地执行,从而实现主从数据库之间数据的同步。 本篇只是简单的列出方案,详细的配置和实现步骤将在另一篇中写到。六、代理的架构方案: 读取内存的速度是读取硬盘的100000-1000000倍。把访问过的页面缓存在内存中,下次直接从内存中读取,可以有效加速。 1、传统代理。客户端发送请求给代理服务器,代理服务器向WEB服务器取到数据并返回给浏览器。代理服务器就是一个有大的存储空间的Cache。 2、反向代理。和传统代理原理类似,只是使用对象不同。传统代理的使用对象是客户端,反向代理的使用对象是服务器。用户通过反向代理访问Web服务器,Web服务器是隐藏起来的。不过用户不关心这些,权把代理服务器当作真实的Web服务器。反向代理有Vamish。七、异步计算的架构方案: 比较耗时的比如将用户上传的文件分发到多台机器,比如裁剪图片,视频转码等。可以使用异步方案。让用户无须等待计算结束而是先行返回结果。代表产品有和Me
2019年07月09日
10,013 阅读
0 评论
2 点赞
2019-07-02
libxml2 configure: error: xml2-config not found. Please check your libxml2 insta
在Linux下,编译安装PHP时报错:libxml2 configure: error: xml2-config not found. Please check your libxml2 installation.但是在Linux下已经安装了libxml2,我通过rpm -qa | grep libxml2就可以查到,那为什么还会提示那个错误呢?应该是libxml2-dev。ubuntu/debian:apt-get install libxml2-devcentos/redhat:yum install libxml2-devel
2019年07月02日
5,115 阅读
0 评论
2 点赞
2019-06-14
php使用unlink删除文件时失败的原因
在做网站的文件上传功能时,遇到了不能删除文件的问题。 我采用的方案是用户先上传到服务器,服务器再上传到阿里云的OSS,中间会有一个把图片临时存储到服务器的过程。使用php的@unlink(删除指定文件)方法时发现了删除失败的问题,很是疑惑。 开始以为是路径名写错了,后来确认路径没有错误并且是绝对路径。删除失败的原因是图片仍然被进程占用,以至于删除失败。 所以想要成功执行unlink操作,我们最好手动释放下文件对象,避免因为被其他线程或进程占用而导致删除失败,小呆萌如下:public function upload() { //获取上传文件 $file = $this->request->file('file'); if ($file) { // 移动文件到 uploads 目录下 $info = $file->rule('date')->move(ROOT_PATH . 'public' . DS . 'uploads'); if ($info) {//文件上传到服务器成功->接下来上传到OSS $filePath = ROOT_PATH . 'public' . DS . 'uploads/' . $info->getSaveName(); $oss = new Oss(); $result = $oss->putObject($filePath); if ($result) { //上传到OSS成功 unset($info);//解除图片的进程占用 @unlink($filePath); return success(['avatar' => $result['fileSrc']], '头像更新成功'); } } } }
2019年06月14日
6,712 阅读
0 评论
52 点赞
2019-05-17
通过酷Q实现qq机器人,实现qq客服、定时推送qq消息、群管理等功能
通过酷Q实现qq机器人,实现qq客服、定时推送qq消息、群管理等功能。方式:1.windows下载酷Q并安装http-api插件。 下载地址:https://pan.baidu.com/s/1qY55zp62.直接使用docker,通过wine运行在linux系统上。$ docker pull richardchien/cqhttp:latest $ mkdir coolq # 用于存储酷 Q 的程序文件 $ docker run -ti --rm --name cqhttp-test \ -v $(pwd)/coolq:/home/user/coolq \ # 将宿主目录挂载到容器内用于持久化酷 Q 的程序文件 -p 9000:9000 \ # noVNC 端口,用于从浏览器控制酷 Q -p 5700:5700 \ # HTTP API 插件开放的端口 -e COOLQ_ACCOUNT=123456 \ # 要登录的 QQ 账号,可选但建议填 -e CQHTTP_POST_URL=http://example.com:8080 \ # 事件上报地址 -e CQHTTP_SERVE_DATA_FILES=yes \ # 允许通过 HTTP 接口访问酷 Q 数据文件 richardchien/cqhttp:latest其中,CQHTTP_POST_URL、CQHTTP_SERVE_DATA_FILES 是用于配置插件运行的,格式为「CQHTTP_ + 插件配置项的大写」,具体的配置项,见 配置。然后访问 http://注意,默认情况下,容器启动时会检查是否已经存在 config 目录,如果不存在,则会将 CQHTTP_ 开头的环境变量写入到配置文件中;如果 config 目录存在,即不是首次启动,则不会做任何修改。因此,你可以在容器运行时手动修改配置文件,重启容器后仍然有效,这和旧版本的行为不一样!如果你要让容器每次启动时都使用环境变量重新创建配置文件,以保持插件行为和容器启动命令的一致性,可以设置环境变量 FORCE_ENV 的值为 true。完成上述配置后即可通过调用api完成qq的发送消息及qq群管理等功能,剩下的具体的业务逻辑使用自己熟悉的语言去实现即可。详细的接口文档:https://richardchien.gitee.io/coolq-http-api/附点餐小呆萌代码:/** * 接收事件上报 * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function receive(){ try{ $getData = input('post.') ? : file_get_contents('php://input'); if (!empty($getData['group_id']) && (int)$getData['group_id'] == $this->groupId) { if ($this->userId = $this->getGroupUserid()){ $content = $getData['raw_message'] ? : $getData['message']; //分离酷q的前置数据与内容文本 preg_match('/(.*[CQ:]{3}.*[]]{1})(.*)/u', $content, $arr); if (!empty($arr[1]) && !empty($arr[2])){ //提取前置数据中被@的qq号 preg_match('/(.*[CQ:at,qq=]{9})([0-9]{5,11})([]]{1})/u', $arr[1], $arr1); if (!empty($arr1[2]) && (int)$arr1[2] == 167114078){ //来到这里证明是被at了,取得纯文本内容进行下一步处理 $tasks = db("group_task") ->whereTime('create_time', 'today') ->select(); if (count($tasks)>=2){ preg_match_all("/([周]{1})([一二三四五六日]{1}).{0,3}([a-cA-C]{1}|[\u{4e0d}]{1}[\u{70b9}]{1})/u", $arr[2],$arr8); $dateArr = $this->getLastSevenDays(); if (!empty($arr8[2])) { //有选项 $data = []; //获取任务id与时间的对应数组,用于判断用户输入的时间有没有任务 $taskArr = array_column($tasks, 'id', 'time'); foreach ($arr8[2] as $key => $value) { $data[strtotime($dateArr[$this->changeDateType($value)])] = $arr8[3][$key]; if (!empty($taskArr[strtotime($dateArr[$this->changeDateType($value)])])){ $taskId = $taskArr[strtotime($dateArr[$this->changeDateType($value)])]; $this->order($taskId, $arr8[3][$key]); }else{ $this->sendGroup($this->groupId, "{$this->groupUserInfo['user_name']}周{$value},没有可点套餐。"); } } }else{ //无选项 preg_match('/([不]{1}[点]{1})/u', $arr[2],$arr2); preg_match('/([A-Ca-c])/u', $arr[2], $arr3); if (!empty($arr2[0]) && $arr2[0] == "不点" || !empty($arr3[0]) && in_array(ucfirst($arr3[0]), ['A', 'B', 'C'])){ $lists = []; $listsNote = []; foreach ($tasks as $v){ $lists[] = "周".$this->changeDateType((int)date("w", $v['time'])); $listsNote[] = "周".$this->changeDateType((int)date("w", $v['time'])) . "-A"; } $msg = "大佬,今天要点" . count($tasks) ."天的餐,你这样我不知道你想点哪一个呀。". PHP_EOL ."今日可点餐有" . implode('、', $lists) . ",点餐请按示例格式回复。". PHP_EOL ."如:" . implode(' ', $listsNote); $this->sendGroup($this->groupId, $msg); } } }else{ if (!empty($tasks[0]['id'])){ preg_match('/([不]{1}[点]{1})/u', $arr[2],$arr2); preg_match('/([A-Ca-c])/u', $arr[2], $arr3); if (!empty($arr2[0]) && $arr2[0] == "不点") { $this->order($tasks[0]['id'], $arr2[0]); exit; }else if (!empty($arr3[0]) && in_array(ucfirst($arr3[0]), ['A', 'B', 'C'])) { $this->order($tasks[0]['id'], ucfirst($arr3[0])); exit; }else { //$this->sendGroup($this->groupId, "不要@我,大佬不给我说话!"); exit; } } } } } } exit; } }catch (\Exception $e){ Log::write("Receive message:".$e->getMessage()); } } /** * 发送消息 * 多行内容部分记得urlencode * @param bool $toUserId * @param bool $content */ public function send($toUserId = false, $content = false){ if ($toUserId && $content){ $content = urlencode($content); $url = "http://127.0.0.1:5701/send_private_msg?user_id={$toUserId}&message={$content}"; file_get_contents($url); } } /** * 发送群消息 * @param bool $groupId * @param bool $message */ public function sendGroup($groupId = false, $message = false){ if ($groupId && $message){ $message = urlencode($message); $url = "http://127.0.0.1:5701/send_group_msg?group_id={$groupId}&message={$message}"; file_get_contents($url); } } /** * 获取群用户id * @return bool|mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ private function getGroupUserid(){ $userModel = db('group_user'); $userInfo = $userModel->where(['qq'=>$this->params['user_id']])->find(); if (isset($userInfo['id'])){ if ((int)$userInfo['status']!=1) return false; $this->groupUserInfo = $userInfo; return $userInfo['id']; } $userParam = $this->params['sender']; $userInfo = [ 'qq' => $userParam['user_id'], 'user_name' => $userParam['nickname'], 'age' => $userParam['age'], 'sex' => $this->getSex($userParam['sex']), 'create_time' => time(), 'update_time' =>time() ]; $this->groupUserInfo = $userInfo; return $userModel->insertGetId($userInfo) ? : false; } private function order($taskId='', $type=''){ try { $type = ucfirst($type); $task = db("group_task") ->find($taskId); if ($task) { $dbModel = db('group_order'); $record = $dbModel ->where([ 'user_id' => $this->userId, 'task_id' => $task['id'] ]) ->find(); $msg = "{$this->groupUserInfo['user_name']},"; if ($record) { $result = $dbModel->update([ 'id' => $record['id'], 'task_id' => $task['id'], 'type' => $this->changeOrderType($type), 'update_time' => time() ]); $msg .= "更新点餐成功,"; } else { $result = $dbModel->insert([ 'user_id' => $this->userId, 'task_id' => $task['id'], 'type' => $this->changeOrderType($type), 'create_time' => time() ]); $msg .= "点餐成功,"; } if ((int)$this->changeOrderType($type) == 9) { $date = $this->changeDateType((int)date("w", $task['time'])); $msg = "{$this->groupUserInfo['user_name']},好的知道了,你周{$date}不点。"; }else if ($result) { $data = json_decode($task['data'], true); $msg .= "您点的是:{$type}餐,【{$data[$type]}】。"; }else{ $msg = "哦吼,点餐失败,系统出错了。"; } $this->sendGroup($this->groupId, $msg); }else{ $this->sendGroup($this->groupId, "{$this->groupUserInfo['user_name']},还没到点餐时间,到时间会通知你的,认真上班吧。"); } }catch (\Exception $e){ $this->sendGroup($this->groupId, "卡bug了,错误信息:".$e->getMessage().'line:'.$e->getLine()); } } /** * 添加点餐任务 * @return mixed */ public function add_task(){ if (request()->isPost()){ $content = input('post.content'); //提取文本中的日期 preg_match_all("'\d{1,2}月\d{1,2}'", $content,$arr1); $time = empty($arr1[0][0]) ? time() : strtotime(date('Y') . '/' . str_replace(['月'], '/', $arr1[0][0])); $dbModel = db("group_task"); $where = [ 'time' => $time ]; $check = $dbModel->where($where) ->find(); if ($check){ $date = date('Y年m月d日', $time); $this->error("{$date},该日期已存在订餐任务,不能重复添加!"); } preg_match_all('/([A-Za-z#].+)/u', $content,$arr); if (!empty($arr[1])) { $result = []; foreach ($arr[1] as $v){ $v = preg_replace("/(\s|\ \;| |\xc2\xa0)/","",$v); $data = explode('餐',$v); if (!empty($data[0]) && in_array($data[0], ['A', 'B', 'C']) && !empty($data[1])) { $result[$data[0]] = $data[1]; } } if (count($result)>=3) { $data = [ 'time' => $time, 'data' => json_encode($result, JSON_UNESCAPED_UNICODE), 'content' => $content, 'create_time' => time() ]; $dbModel->insert($data); $this->success('添加点餐任务成功!'); } } $this->error('添加任务失败!'); exit; } return $this->fetch(); } /** * 推送qq消息 */ public function push_message(){ if (request()->isPost()) { $content = input('post.content'); $this->sendGroup($this->groupId, $content); //$this->sendGroup($this->groupId, "来活了,老铁们,开始点餐啦,A、B、C随便选,不点的回复不点,点餐时需要先@小助手,否则不管用哦,点餐12点准时结束,过时不候。"); $this->success("推送成功!"); } return $this->fetch(); } /** * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function views(){ $userModel = db('group_user'); $day = input("param.day") ? : (date('d')); $startTime = strtotime(date("Y-m-{$day} 00:00:00")); $task = db("group_task") ->where(['time'=> $startTime]) ->find(); $data = empty($task['id'])? [] : $userModel->alias('u') ->field("u.id,u.user_name,o.type,o.create_time") ->join("group_order o", "o.task_id = {$task['id']} and o.user_id = u.id", 'LEFT') ->where(['u.status' => 1]) ->order("o.type asc") ->select(); $result = $this->array_group_by($data, 'type'); $notChoose = isset($result['']) ? implode(',', array_column($result[''], 'user_name')) : ''; $this->assign('not_choose', $notChoose); ksort($result); $record = []; $msg = []; foreach ($result as $k => $v){ if (!empty((int)$k) && in_array((int)$k, [1,2,3])){ $num = count($v); $msg[] = $this->changeOrderType($k) ." {$num}份"; $record[$k] = $num; } } $info = '云商项目开发部: '.implode(', ', $msg) . " 共计:".array_sum($record) . "份"; foreach ($data as $k => &$v){ if (!empty($v['type']) && in_array((int)$v['type'], [1, 2, 3])){ $v['status'] = 1; }else{ $v['status'] = ''; } $v['type'] = $this->changeOrderType($v['type']); if ($v['create_time']){ $v['create_time'] = date('Y-m-d H:i:s', $v['create_time']); } } krsort($msg); if (request()->isPost()){ $result = [ 'code' => 0, 'data' => $data ]; echo json_encode($result); exit; } if ($task){ $task = json_decode($task['data'], true); } $days = date('t', strtotime('Y-m')) + 1 ; $this->assign('days', $days); $this->assign('day', $day); $this->assign('task', $task); $this->assign('data', $data); $this->assign('info', $info); return $this->fetch(); } /** * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function view_month(){ $days = date('t', strtotime('2019-03')); $userModel = db('group_user'); $orderModel = db('group_order'); $month = input("param.month") ? : date('m'); if (request()->isPost()){ $startTime = strtotime(date("Y-{$month}-1")); $endTime = strtotime(date("Y-m-d", strtotime("last day of this month", strtotime(date("Y-{$month}-d"))))); $data = $userModel ->field("id,user_name") ->where(['status' => 1]) ->select(); foreach ($data as &$v){ $results = $orderModel->alias('o')->field("t.time") ->join('group_task t', "t.id = o.task_id", "LEFT") ->where([ 'o.user_id' => $v['id'], 't.time' => ['between', [$startTime, $endTime]], 'o.type' => ['IN', [1,2,3]] ])->select(); $v['type'] = "午餐"; $timeArr = array_column($results, 'time'); for ($i=1;$i 0, 'data' => $data ]; echo json_encode($result); exit; } $this->assign('months', [1,2,3,4,5,6,7,8,9,10,11,12]); $this->assign('month', $month); return $this->fetch(); } public static function array_group_by($arr, $key) { $grouped = []; foreach ($arr as $value) { $grouped[$value[$key]][] = $value; } if (func_num_args() > 2) { $args = func_get_args(); foreach ($grouped as $key => $value) { $parms = array_merge([$value], array_slice($args, 2, func_num_args())); $grouped[$key] = call_user_func_array('array_group_by', $parms); } } return $grouped; } /** * 点餐结束,推送点餐情况 * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function push_order_result(){ if (!empty($this->params['token']) && $this->params['token'] == $this->push_token) { $task = db("group_task") ->whereTime('create_time', 'today') ->select(); if ($task) { $userModel = db('group_user'); $msg = '今日点餐时间结束,点餐情况如下:'.PHP_EOL; foreach ($task as $v){ $orderDate = date('Y年m月d日', $v['time']); $msg .= "用餐时间:{$orderDate}".PHP_EOL; $data = $userModel->alias('u') ->field("u.id,u.user_name,o.type,o.create_time") ->join('group_order o', "o.user_id = u.id and task_id = {$v['id']}", 'LEFT') ->where(['u.status' => 1]) ->select(); $orderData = json_decode($v['data'], true); foreach ($data as $vo){ if (!empty($vo['type']) && in_array((int)$vo['type'], [1,2,3])){ $type = $this->changeOrderType($vo['type']); $msg .= "{$vo['user_name']} : {$type}餐 【{$orderData[$type]}】".PHP_EOL; }else{ $msg .= "{$vo['user_name']} : 不点".PHP_EOL; } } $result = $this->array_group_by($data, 'type'); $typeMsg = []; $record = []; foreach ($result as $k => $v){ if (!empty((int)$k) && in_array((int)$k, [1,2,3])){ $num = count($v); $typeMsg[$k] = $this->changeOrderType($k) ." {$num}份"; $record[$k] = $num; } } ksort($typeMsg); $msg .= PHP_EOL."{$orderDate} 云商项目开发部: ".implode(', ', $typeMsg) . " 共计:".array_sum($record) . "份".PHP_EOL; } $this->sendGroup($this->groupId, $msg); } } } /** * 开饭前推送今天的点餐情况 * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function push_today_order(){ if (!empty($this->params['token']) && $this->params['token'] == $this->push_token) { $task = db("group_task") ->whereTime('time', 'today') ->find(); if ($task){ $userModel = db('group_user'); $orderDate = date('m月d日', $task['time']); $msg = "下班开饭,{$orderDate}点餐情况如下,请对号入座:".PHP_EOL; $data = $userModel->alias('u') ->field("u.id,u.user_name,o.type,o.create_time") ->join('group_order o', "o.user_id = u.id and task_id = {$task['id']}", 'LEFT') ->where(['u.status' => 1]) ->select(); $orderData = json_decode($task['data'], true); foreach ($data as $vo){ if (!empty($vo['type']) && in_array((int)$vo['type'], [1,2,3])){ $type = $this->changeOrderType($vo['type']); $msg .= "{$vo['user_name']} : {$type}餐 【{$orderData[$type]}】".PHP_EOL; }else{ $msg .= "{$vo['user_name']} : 不点".PHP_EOL; } } //$msg .= PHP_EOL."你喜欢岁月静好,其实现实是大江奔流。"; $this->sendGroup($this->groupId, $msg); } } } /** * 获取未来7天分别是周几 * @param bool $time * @return array */ public function getLastSevenDays($time = false){ if (!$time) $time = time(); $data = []; for ($i=0;$i<7;$i++){ $data[date('w', $time)] = date('Y-m-d 00:00:00', $time); $time += 60*60*24; } return $data; } /** * 把中文的周几转换为数字并对应php date()方法 * @param string $date * @return bool|int */ public function changeDateType($date = ''){ $result = false; if (is_int($date)){ switch ($date){ case 1: $result = '一'; break; case 2: $result = '二'; break; case 3: $result = '三'; break; case 4: $result = '四'; break; case 5: $result = '五'; break; case 6: $result = '六'; break; case 0: $result = '日'; break; } }else{ if (empty($date)) return $result; switch ($date){ case '一': $result = 1; break; case '二': $result = 2; break; case '三': $result = 3; break; case '四': $result = 4; break; case '五': $result = 5; break; case '六': $result = 6; break; case '日': $result = 0; break; } } return $result; }
2019年05月17日
7,442 阅读
0 评论
46 点赞
2019-04-10
mysql优化之thread_cache_size
1、mysql服务器的线程数查看方法:show global status like 'Thread%';Threads_created:创建过的线程数,如果发现Threads_created值过大的话,表明MySQL服务器一直在创建线程,这也是比较耗资源,可以适当增加配置文件中thread_cache_size值2、优化参数thread_cache_sizethread_cache_size:当客户端断开之后,服务器处理此客户的线程将会缓存起来以响应下一个客户而不是销毁(前提是缓存数未达上限)即可以重新利用保存在缓存中线程的数量,当断开连接时如果缓存中还有空间,那么客户端的线程将被放到缓存中,如果线程重新被请求,那么请求将从缓存中读取,如果缓存中是空的或者是新的请求,那么这个线程将被重新创建,如果有很多新的线程,增加这个值可以改善系统性能。thread_cache_size大小的设置:如果是短连接,适当设置大一点,因为短连接往往需要不停创建,不停销毁,如果大一点,连接线程都处于取用状态,不需要重新创建和销毁,所以对性能肯定是比较大的提升。对于长连接,不能保证连接的稳定性,所以设置这参数还是有一定必要,可能连接池的问题,会导致连接数据库的不稳定性,也会出现频繁的创建和销毁,但这个情况比较少,如果是长连接,可以设置成小一点,一般在50-100左右。物理内存设置规则:通过比较Connections 和 Threads_created 状态的变量,可以看到这个变量的作用。(-->表示要调整的值) 根据物理内存设置规则如下: 1G ---> 8 2G ---> 16 3G ---> 32 >3G ---> 64查询thread_cache_size设置show global status like'thread_cache_size';优化方法:1、mysql> set global thread_cache_size=162、编辑/etc/my.cnf 更改/添加thread_concurrency = 163、mysql kill线程mysqladmin start slave stop slave kill某个连接到mysqlServer的线程
2019年04月10日
5,962 阅读
0 评论
49 点赞
1
...
5
6
7
8