- 博客(79)
- 收藏
- 关注
原创 数组分割处理
$arr = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]; $arr_chunk = array_chunk($arr,5,true);//数组分割 $new_arr = []; $count = count($arr_chunk); for ($i=0;$i<$count;$i++){ foreach ($arr_chunk[$i] as $ke
2022-05-10 10:36:27 108
原创 tp5 group分组后的排序问题
$user_notice = $this->where('uid',$uid) ->group('type')->field('id,type,is_read,title as notice_title,create_time')->order('create_time desc') ->select()->toArray(); //查询最后一条数据 $cod = $this->wher.
2022-04-12 14:34:49 1873
原创 异步处理支付宝提现订单
<?phpnamespace app\command;use app\admin\model\ChargeOrder;use app\admin\model\ExtractApply;use app\admin\service\AdminLogService;use app\common\exception\ExtractException;use app\common\lib\Jwt;use app\common\lib\Predis;use app\index\model\Use
2022-01-27 20:41:42 589
原创 tp5 闭包函数
//判断屏蔽商品,只有自己能看见自己的屏蔽商品 if(!empty($params["uid"])) { $uid = $params['uid']; $model->where(function ($query) use ($uid){ $query->where(Db::raw("((uid != $uid AND is_shield = 0) OR uid = $uid.
2022-01-25 11:52:42 405
原创 redis 锁
foreach ($list as $key=>$value){ //redis 加锁 $cacheKey = 'settlement_order_' . $value['id']; if (Predis::getInstance()->get($cacheKey)) { throw new Extra.
2022-01-24 20:50:59 800
原创 php二维数组相同日期分类处理
array(4) { [0] => array(3) { ["total_count"] => string(2) "17" ["device"] => string(2) "pc" ["date"] => string(10) "2021-12-27" } [1] => array(3) { ["total_count"] => string(1) "2" ["device"] => string(2) "pc"
2021-12-28 17:49:44 365 1
原创 tp数据排序,分片处理分页
//排序 1正序2倒序 if (isset($data['upvote_type'])){ $orderStr = 'upvote'; $orderType = $data['upvote_type'] == '1' ? SORT_ASC : SORT_DESC; }elseif (isset($data['brower_type'])){ $orderStr = 'brower'; .
2021-12-20 17:10:03 394
原创 tp5.* 分布式事务报错不回滚问题
基于mysql的事务特性:事务必须是在同一个数据库连接中才能生效。tp5.*中的事务也必须在同一个数据库连接当中。但是!重点来了,如果在tp5.*的模型属性中配置了$connection属性(这个属性的用途大家可以自行到开发手册上查)就会导致每次实例化不同模型的时候,就会创建不同的数据库连接,导致事务并未在同一个数据库连接中执行,自然就会导致事务无法正确回滚。举个例子://假设模型A、模型B都配置了$connection属性$modelA = new A();$modelB = new B();
2021-12-14 20:15:37 779
原创 PHP模型事务使用
<?php/** * 模型事务测试 * MyISAM:不支持事务,主要用于读数据提高性能I* InnoDB:支持事务、行级锁和并发 */public function transaction(){ $modelA = model('A'); $modelA->startTrans(); // 开启事务A $result = $modelA->save($data1); if($result === false){
2021-12-14 15:49:15 146
原创 php 导出CSV格式数据
/** * * 导出数据.csv格式 */ public function export() { set_time_limit(0); ini_set('memory_limit', '128M'); $fileName = date('YmdHis', time()); header('Content-Encoding: UTF-8'); header("Content-typ.
2021-12-02 14:47:01 227
原创 PHP二维数组赋值
/** * 二维数组赋值 */ public function test2() { $a = [ ['id'=>1,'uid'=>101,'order_id'=>001], ['id'=>2,'uid'=>102,'order_id'=>002], ['id'=>3,'uid'=>103,'order_id'=>003],..
2021-11-23 11:46:53 755
原创 PHP 将金额转换成中文大写
/** * 将数值金额转换为中文大写金额 * @param $amount float 金额(支持到分) * @param $type int 补整类型,0:到角补整;1:到元补整 * @return mixed 中文大写金额 */ public function convertAmountToCn($amount, $type = 0) { // 判断输出的金额是否为数字或数字字符串 if(!is_n...
2021-11-11 15:30:40 99
原创 tp5.1实现wokerman聊天室
<?phpnamespace app\worker;use think\worker\Server;use Workerman\Lib\Timer;class Worker extends Server{ protected $socket = 'websocket://127.0.0.1:2000'; protected $HEARTBEAT_TIME = 30;//心跳时间 /** * 收到消息时 * @param $connection
2021-11-03 15:04:21 263
原创 Git常用命令
Git安装:sudo apt-get install gitGit设置:git config --global user.name "Your Name"git config --global user.email "[email protected]"创建版本库:mkdir gitgit init //变成Git管理仓库提交:git status //查看状态git add //添加到暂存区git commit -m 'xxx' //提交到当前分支git pull //拉取
2021-10-21 14:49:52 62
转载 docker exec进入容器报错could not create session key: function not implemented“: unknown
WSL安装和运行docker服务Linux子系统(Windows Subsystem for Linux ,WSL)可以在Windows中运行Linux环境。它并不是虚拟机,只是一个模拟环境,并不能完全实现Linux中的各种操作,但是其启动速度非常快,与windows交互非常方便,消耗非常低,比虚拟机省去大把内存,非常适合本地开发时使用。此前在WSL里面不能使用Linux版的docker,需要安装Windows版与其通信,但Windows版是个大坑,而且资源占用很高。最近发现,从win10创新者更新后
2021-10-15 16:24:27 826
原创 解决docker: Error response from daemon: OCI runtime create failed版本不兼容问题
一、问题描述docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "process_linux.go:301: running exec setns process for init caused \"exit status 23\"": unknown.二、产生这个问题的原因目前我使用的Ubuntu的版本是18.
2021-09-28 19:12:50 6212 1
原创 ubantu 启动docker报错 Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker
在windows 10 上通过 Ubuntu 18.04 测试docker,在终端执行sudo docker start 之后报错Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?之后查看/var/log/docker.log有以下报错:failed to create NAT chain DOCKER: iptables failed: iptables -
2021-09-28 14:17:48 1017 2
原创 PHP RabbitMQ简单使用
<?phpnamespace app\index\controller;use think\Cache;use think\Controller;use PhpAmqpLib\Connection\AMQPStreamConnection;use PhpAmqpLib\Message\AMQPMessage;use think\App;use think\Db;class Rabbitmq extends Controller{ protected $redis_cli
2021-09-18 16:00:02 184 1
原创 PHP压缩文件处理中文乱码
//下载PHP扩展pclzip1.composer require pclzip/pclzip//处理中文乱码加上pclzip.lib.php 第3517行 $p_entry['filename'] = $p_path . "/" . $p_entry['filename'];//加上下面代码2.$p_entry['filename'] = mb_convert_encoding($p_entry['filename'], 'UTF-8', 'gb2312'); /** * 文件上传
2021-07-22 14:22:17 224 1
原创 PHP 下载压缩文件
array(2) { [0] => array(2) { ["img"] => string(111) "/Uploads/Staff/绍兴/测试/1626231191SDoQId.jpg,/Uploads/Staff/绍兴/测试/1626231191ikHoYb.jpg" ["k"] => string(6) "测试" } [1] => array(2) { ["img"] => string(111) "/Uploads/Staff/绍兴
2021-07-14 16:06:30 532 3
原创 PHP 上传压缩文件
private function uploadBiye($zipfile, $filepath) { $zip = new \ZipArchive(); if ($zip->open($zipfile) === TRUE) {//中文文件名要使用ANSI编码的文件格式 // 加入此段↓ $fileNum = $zip->numFiles; for ($i = 0; $i < $file.
2021-07-13 09:16:22 637
原创 博客学习资料
## Ubuntu 18.04上nginx+php环境搭建https://blog.csdn.net/qq_36290650/article/details/90411807
2021-06-30 17:07:10 158
原创 二维数组处理键值做key
$day = GameRecommend::where('shelf_time','>',time())->where('create_time','between',[$before_time,$after_time]) ->field('create_time')->group("FROM_UNIXTIME(`create_time`,'%Y-%m-%d')")->select()->toArray(); $game_.
2021-06-23 13:22:18 387
原创 php 获取器修改器
<?phpnamespace app\index\model;use think\Model;class User extends Model{ protected $append = ['status_text'];//添加不存在的字段 protected $autoWriteTimestamp = true;//时间转换 //获取器对状态值进行转换 public function getStatusAttr($value) {
2021-06-19 17:21:58 179 4
原创 PHP 树形结构tree
array(18) { [0] => array(5) { ["id"] => int(3) ["title"] => string(12) "游戏管理" ["uri"] => string(11) "/gameManage" ["state"] => int(1) ["pid"] => int(0) } [1] => array(5) { ["id"] => int(9) ["title"]
2021-06-11 17:50:42 639 3
原创 php 数组数据合并,拆分,赋值
array(7) { [0] => array(7) { ["s_day"] => string(10) "2021-06-09" ["total_amount"] => string(6) "666.00" ["order_num"] => int(1) ["people_num"] => int(1) ["total_service_amount"] => string(5) "33.30" ["service_am
2021-06-11 14:12:15 103
原创 数据查询group和FROM_UNIXTIME的使用
$on_sell_log['device_type'] = Db::name('charge_commodity')->where($where2)->where('del',0)->where('status','in','1,3') ->group("FROM_UNIXTIME(create_time,'$date2'),`platform` ") ->field("create_time,FROM_UNIXTIME(crea
2021-06-10 14:29:40 179
原创 负载均衡简单配置
1、负载均衡一台计算机的计算资源是有效的,当超大流量请求时,就可能导致请求等待或者服务器死机的情况,为了解决大流量访问的问题,可以搭建分布式,将请求分发到不同计算机,就可以解决大流量请求的问题。长见的负载均衡方案有如下几种:1、http重定向2、反向代理负载均衡3、IP负载均衡4、DNS负载均衡5、DNS/GSLB负载均衡对于一般的大流量请求,会用到nginx反向代理,下面将主要介绍如何搭建nginx反向代理的架构;那么负载均衡的前提就是要有多台服务器才能实现,也就是两台以上即可,本次用
2021-05-14 10:49:19 1355 1
原创 服务器高并发处理
1.静态化页面效率最高、消耗最少的就是纯静态化的html页面。对于一些更新频率不频繁而又被大量访问的页面,我们就可以做静态化处理,来避免大规模的数据库访问。2.图片服务器分离不管是什么服务器,图片都是最消耗资源的。当然还有视频,面对大数据量的访问,很可能因为图片问题而造成服务器崩溃。那么就有必要将图片和页面进行分离。把图片、视频放到独立的甚至是多台服务器里。这样可以降低页面访问请求的服务器系统的压力,并且保证系统不会因为图片问题而崩溃。3.通过缓存加速数据库的访问。大部分的网站都是符合二八原则
2021-05-14 10:24:40 258
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人