分类目录归档:Tools

php redis连接数过多解决办法(Yii,predis,phpredis等)

Yii redis 持久配置

   'redis' => [
            'class' => 'yii\redis\Connection',
            'hostname' => '127.0.0.1',
            'retries' => 3,
            'port' => 6379,
            'password' => '',
            'socketClientFlags' => STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT,
        ],

predis redis 持久配置

  $client = new \Predis\Client([
            'scheme' => 'tcp',
            'host' => $redis->hostname,
            'port' => $redis->port,
            'password' => $redis->password,
            'persistent'=>true,
        ]);

phpredis redis 持久配置

$redis->pconnect('127.0.0.1', 6379);

使用MSYS2+mingw+QT作为C++开发环境

 下载msys2

在中国科学技术大学镜像站点http://mirrors.ustc.edu.cn/msys2/distrib/下载最新版32(i686)/64(x86_64)位系统msys2

下载后安装

修改软件源

msys2采用pacman管理软件包,修改pacman的软件源提高下载速度

pacman的配置
编辑 /etc/pacman.d/mirrorlist.mingw32 ,在文件开头添加:

Server = http://mirrors.ustc.edu.cn/msys2/mingw/i686/
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/i686/
Server = http://mirror.bit.edu.cn/msys2/mingw/i686/
Server = https://mirrors.sjtug.sjtu.edu.cn/msys2/mingw/i686/

编辑 /etc/pacman.d/mirrorlist.mingw64 ,在文件开头添加

Server = http://mirrors.ustc.edu.cn/msys2/mingw/x86_64/
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/x86_64/
Server = http://mirror.bit.edu.cn/msys2/mingw/x86_64/
Server = https://mirrors.sjtug.sjtu.edu.cn/msys2/mingw/x86_64/

编辑 /etc/pacman.d/mirrorlist.msys ,在文件开头添加

Server = http://mirrors.ustc.edu.cn/msys2/msys/$arch/
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/msys/$arch/
Server = http://mirror.bit.edu.cn/msys2/msys/$arch/
Server = https://mirrors.sjtug.sjtu.edu.cn/msys2/msys/$arch/

然后执行 pacman -Sy 刷新软件包数据即可。

安装开发环境

安装基本开发环境和常用工具

pacman -S  base-devel  git  wget  p7zip  perl ruby python

安装 32位 MinGW-w64

pacman -S  mingw-w64-i686-toolchain

安装 64位 MinGW-w64

pacman -S  mingw-w64-x86_64-toolchain

安装Qt5和Qt Creator

pacman -S mingw64/mingw-w64-x86_64-qt5 mingw64/mingw-w64-x86_64-qt-creator

参考

GlitchTip – 开源的Sentry API兼容的错误跟踪系统

GlitchTip is an open source, Sentry API compatible error tracking platform. It is a partial fork/partial reimplementation of Sentry's open source codebase before it went proprietary. Its goals are to be a modern, easy-to-develop error tracking platform that respects your freedom to use it any way you wish. Some differences include:

A modern development environment with Python 3 and Django 3.1.
Simplicity over features. We use Postgres to store error data. Our code base is a fraction of the size of Sentry and looks like a typical Django app. We leverage existing open source Django ecosystem apps whenever possible.
Respects your privacy. No massive JS bundles. No invasive tracking. No third party spying. Even our marketing site runs Matomo and respects Do Not Track. GlitchTip will never report home. We will never know if you run it yourself.
Commitment to open source. We use open source tools like GitLab whenever possible. With our MIT license, you can use it for anything you'd like and even sell it. We believe in competition and hope you make GlitchTip even better.

Project status: Stable. Open an issue and say hello if you'd like to help. We are able to process basic error requests from the open source Sentry client tools. More features are on the way.

参考

PHP AMQP 使用指南

为什么要使用消息队列?

提速

使用了消息队列,生产者一方,把消息往队列里一扔,就可以立马返回,响应用户了。无需等待处理结果。

处理结果可以让用户稍后自己来取,如医院取化验单。也可以让生产者订阅(如:留下手机号码或让生产者实现listener接口、加入监听队列),有结果了通知。获得约定将结果放在某处,无需通知。

解耦

考虑电商系统下订单,发送数据给生产系统的情况。电商系统和生产系统之间的网络有可能掉线,生产系统可能会因维护等原因暂停服务。如果不使用消息队列,电商系统数据发布出去,顾客无法下单,影响业务开展。两个系统间不应该如此紧密耦合。应该通过消息队列解耦。同时让系统更健壮、稳定。

消除峰值

消息存在队列中,等待高峰期过后再处理

广播

多个客户端可以订阅同一个TOPIC,或者多个worker轮询并发执行任务

CentOS 安装 RabbitMQ

安装并启动rabbitmq

yum install rabbitmq-server
systemctl start rabbitmq-server
systemctl status rabbitmq-server
systemctl enable rabbitmq-server
rabbitmq-plugins enable rabbitmq_management

启动管理后台插件

rabbitmq-plugins enable rabbitmq_management

添加管理账户

rabbitmqctl add_user admin password
rabbitmqctl set_user_tags admin administrator
rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"

开启端口

amqp端口是 5672 , 管理后台是 15672

RabbitMQ management API

https://rawcdn.githack.com/rabbitmq/rabbitmq-management/v3.8.9/priv/www/api/index.html

可以通过API管理RabbitMQ服务器

PHP的amqp扩展

php-amqplib 纯PHP库

https://github.com/php-amqplib/php-amqplib

composer 安装

composer require php-amqplib/php-amqplib

perl c扩展

https://pecl.php.net/package/amqp

linux 编译安装

pecl install amqp

centos yum remi库安装

 yum install php74-php-pecl-amqp

windows dll 安装

https://pecl.php.net/package/amqp

下载后php_amqp.dll放到ext目录,rabbitmq.4.dll放在php目录,修改php.ini添加extension=php_amqp.dll

使用AMQP

https://www.rabbitmq.com/tutorials/tutorial-one-php.html

参考

公众号回复小技巧

用户点击后自动触发回复

<a href="weixin://bizmsgmenu?msgmenucontent={{自动回复内容}}&msgmenuid={{自己维护一个不重复的 ID}}">{{自动回复内容}}</a>

file

回复小程序超链接

 <a data-miniprogram-appid="wx5ba8812bdfc7741f" data-miniprogram-path="amouse_wxapp_card/pages/card/home/home" href="http://www.qq.com">5万运营都在用的 运营名片小程序</a>

file

发送小程序卡片(要求小程序与公众号已关联)

参考:(https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Service_Center_messages.html#7

{
    "touser":"OPENID",
    "msgtype":"miniprogrampage",
    "miniprogrampage":
    {
        "title":"title",
        "appid":"appid",
        "pagepath":"pagepath",
        "thumb_media_id":"thumb_media_id"
    }
}

file

使用 WSL 作为开发环境 (Ubuntu+PostgreSQL+MariaDB/Mysql+PHP+Python+NodeJS+镜像安装)

安装后配置

修改DNS

/etc/resolv.conf

nameserver 223.5.5.5

修改软件源

一般情况下,将 /etc/apt/sources.list 文件中 Ubuntu 默认的源地址 http://archive.ubuntu.com/ 替换为 http://mirrors.ustc.edu.cn 即可。

可以使用如下命令:

sudo sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list

更新包

sudo apt update
sudo apt upgrade

PostgreSQL

新增apt源配置

新增配置文件 /etc/apt/sources.list.d/pgdg.list,内容:

deb https://mirrors.ustc.edu.cn/postgresql/repos/apt/ focal-pgdg main

bionic可以换成去其他版本号

导入key并安装

wget --quiet -O - https://mirrors.ustc.edu.cn/postgresql/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt install postgresql-12
sudo systemctl enable postgresql
sudo service start postgresql

创建数据库以及账户

切换到postgres用户并运行psql

sudo -u postgres psql

创建数据以及用户账户

CREATE USER c4ys WITH PASSWORD 'c4ys';
CREATE DATABASE c4ys OWNER c4ys;

MariaDb

下载key

sudo apt-get install software-properties-common
sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] https://mirrors.ustc.edu.cn/mariadb/repo/10.5/ubuntu focal main'
sudo apt update
sudo apt install mariadb-server

将源配置修改到单独文件

系统会自动在source.list增加配置,可以将配置移动到单独文件

/etc/apt/sources.list.d/MariaDB.list

deb [arch=ppc64el,arm64,amd64] https://mirrors.ustc.edu.cn/mariadb/repo/10.5/ubuntu focal main
# deb-src [arch=ppc64el,arm64,amd64] https://mirrors.ustc.edu.cn/mariadb/repo/10.5/ubuntu focal main

自动启动

sudo systemctl enable mariadb
sudo service mariadb start
sudo mysql_secure_installation

Python

将python3作为默认Python

sudo apt install python-is-python3  python3-pip

参考

将chrome的copy as cURL转换成Python、PHP、Go等十多种语言代码

chrome提供了非常方便的复制功能,可以将页面请求复制为curl命令行或者nodejs fetch等。那么,能不能得到其他比如PHP,Go,Python版本的代码呢?答案是可以,且只需两步。

获取curl代码

在 Chrome 开发工具的网络选项卡中,右键单击请求,然后单击“复制” > “复制为 cURL (命令)”。

file

得到

curl 'https://c4ys.com/' -H 'authority: c4ys.com'...

将cURL命令转化成其他语言代码

浏览器打开 https://cURL.trillworks.com/ 就可以将 cURL 命令转换成 Python、 NodeJS 、Go、 PHP等十多个语言版本了。

file

Windows Terminal支持ssh,git-bash,wsl

打开 profiles.json 配置文件

打开Windows Terminal,点击设置,可以看到,复制增加一组ssh配置,然后修改三个地方。

{
// Make changes here to the powershell.exe profile.
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "Windows PowerShell",
"commandline": "powershell.exe",
"hidden": false
},

修改guid

利用powershell可以生成guid

powershell -Command "[guid]::NewGuid().ToString()"

修改名字

任意,可以是系统名字,IP,用户名等,如 username@aliyun-bj

修改commandline

ssh -i C:\user\username\id_rsa username@aliyun-bj

其中i参数后面为证书存放位置,如果试用密码登录可以不填

完整SSH支持(图标,配色等)

 {
     "acrylicOpacity" : 1,
     "closeOnExit" : true,
     "colorScheme" : "One Half Dark",
     "commandline" : "ssh username@aliyun-bj",
     "cursorColor" : "#FFFFFF",
     "cursorShape" : "bar",
     "fontFace" : "Consolas",
     "fontSize" : 14,
     "guid" : "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
     "historySize" : 9001,
     "icon" : "ms-appx:///ProfileIcons/{9acb9455-ca41-5af7-950f-6bca1bc9722f}.png",
     "name" : "username@aliyun-bj",
     "padding" : "0, 0, 0, 0",
     "snapOnInput" : true,
     "startingDirectory" : "",
     "useAcrylic" : false
 }

 支持Git-bash

{
            "guid": "{7f0152b2-c491-4bb6-8a87-610352d630c8}",
            "acrylicOpacity" :1,
            "closeOnExit" : true,
            "colorScheme" : "Campbell",
            "commandline" : "\"%PROGRAMFILES%\\Git\\Bin\\bash.exe\" -i -l",
            "cursorColor" : "#FFFFFF",
            "cursorShape" : "bar",
            "fontFace" : "Consolas",
            "fontSize" : 14,
            "historySize" : 9001,
            "icon" : "%PROGRAMFILES%\\Git\\mingw64\\share\\git\\git-for-windows.ico",
            "name" : "Git-bash",
            "padding" : "0, 0, 0, 0",
            "snapOnInput" : true,
            "startingDirectory" : "%USERPROFILE%",
            "useAcrylic" : true
        }

WSL

        {
            "guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
            "hidden": false,
            "name": "Ubuntu",
            "source": "Windows.Terminal.Wsl"
        },

参考