分类: 编程

  • MySQL8 GTID双主配置

    记录一下MySQL8中配置GTID双主的方式。

    需要添加以下配置信息:

    vim /etc/my.cnf
    # 添加
    [mysqld]
    # 两台服务器的server-id不能一致
    server-id=1
    gtid_mode=on
    enforce-gtid-consistency=true
    

    具体使用到的SQL语句:

    # 创建一个账号用于另一台主机复制数据
    # create user 'slave'@'0.0.0.0' identified by 'this is your password';
    
    # 授权
    grant REPLICATION SLAVE on *.* to 'slave'@'0.0.0.0';
    
    # 查看主机状态
    SHOW MASTER STATUS;
    
    # 以下为另一台服务器执行内容
    CHANGE REPLICATION SOURCE to
        SOURCE_HOST = '0.0.0.0',
        SOURCE_PORT = 3306,
        SOURCE_USER = 'slave',
        SOURCE_PASSWORD = 'this is your password';
    
    # 停止并重置复制
    STOP REPLICA;
    reset REPLICA;
    
    # 开始复制并查看复制状态
    START REPLICA;
    SHOW REPLICA STATUS;
    
  • PHP内置服务器与Serverless

    PHP从5.4版本开始就提供了一个内置的WEB服务器,可以通过一个简单的命令php -S启动一个WEB服务器,极大简化了开发环境的搭建。

    到目前为止,官网文档对于内置服务器的使用依然建议用于开发环境,不建议用于生产环境,原因倒是很容易理解,主要有两个方面:

    1. 支持的MIME类型很少,5.4版本放出时只支持.htm和.svg(从5.5版本完善了大部分常见的MIME类型支持)

    2. 仅实现了基本功能,基本没有任何优化,是一个单线程进程(不过从7.4版本开始,内置服务器支持多进程的运行方式)

    从传统开发角度看,这样性能和功能的服务器确实很难应用于生产环境,但是伴随着Serverless的发展,感觉内置服务器的限制突然不是那么重要了。

    使用Serverless服务,不管是AWS Lambda,Google Function,还是国内阿里云的函数计算、腾讯云的云函数,我们关注的点不再聚焦于单机性能释放,而是变成了以下四个方面,我们要做的本质上变成了降低单请求的资源占用和执行时间

    1. 调用次数

    2. CPU时间

    3. 内存占用

    4. 执行时间

    5. 带宽

    我们可以逐个对比以下,

    1. 调用次数显然很难因为WEB服务器的变化有什么变化

    2. CPU时间上,内置服务器作为一个单进程应用,同样的逻辑在函数计算这样的环境下,较少了Nginx与FPM交互的网络开销、Nginx的运行开销,理论上内置服务器应该表现更好

    3. 内存占用方面,内置服务器不再需要运行Nginx,同样逻辑,应该也比传统部署方式占用更少一些

    4. 执行时间,Nginx+FPM需要启动两个进程,需要两个进程间的通信,很难与直接启动PHP进程更快

    5. 带宽基本不用对比,应该不会有什么变化,gzip完全可以在CDN层来实现

    从Serverless的角度看,内置服务器并不算是一个很差的选择,对比传统的运行方式可能更加合适一些,就是不太清楚不建议生产环境使用是否有除性能外的其他原因,回头去翻一翻PHP的issue。

    参考文章

    1. PHP-Built-in web server(https://www.php.net/manual/en/features.commandline.webserver.php

  • Nextcloud安全最佳实践

    1. 复杂密码
    2. Suspicious Login
    3. 两步认证,启用至少一项
      1. *Two-Factor TOTP Provider
      2. *Two-Factor Authentication via Nextcloud Notification
      3. *Two-Factor WebAuthn
      4. Two-Factor Email
  • PostgreSQL常用SQL语句

    PostgreSQL与MySQL语法有一些细微差异,记录一下PostgreSQL常用的SQL语句。

    1. 创建数据库、用户,并授予用户权限

    # 创建用户并指定owner(不指定owner,对应的用户授权了也看不见)
    CREATE DATABASE xxx owner xxx;
    create user test with password 'test';
    
    # 授权
    GRANT ALL PRIVILEGES ON DATABASE xxx TO xxx;
    GRANT ALL PRIVILEGES ON all tables in schema public TO xxx;
    GRANT ALL ON SCHEMA public TO xxx;
    GRANT USAGE ON SCHEMA public TO xxx;
    
    # 重载配置,让修改生效
    SELECT pg_reload_conf();
    

    2. 删除数据库

    如果有授权信息,删除数据库时会报错,要删除数据库需要先取消授权。

    # 禁止连接
    UPDATE pg_database 
    SET datallowconn = 'false' 
    WHERE datname = 'xxx';
    
    # 关闭已连接进程
    SELECT pg_terminate_backend(pid)
    FROM pg_stat_activity
    WHERE datname = 'xxx';
    
    # 取消授权并删除用户
    revoke all on database postgres from xxx;
    revoke all on all tables in schema public from xxx;
    revoke all on schema public from xxx;
    revoke usage on schema public from xxx;
    
    # 删除用户(不取消授权也无法删除用户)
    drop role xxx;
    
    # 重载配置,让修改生效
    SELECT pg_reload_conf();
    

    3. 重命名用户、数据库

    # 重命名用户
    ALTER USER name RENAME TO new_name;
    
    # 重命名数据库
    ALTER DATABASE name RENAME TO new_name;
    

    4. 修改密码

    ALTER USER xxx WITH PASSWORD 'xxx';
    

    5. 其他常用

    # 统计当前所有连接数
    select count(1) from pg_stat_activity;
    
    # 查询当前连接数详细信息
    select * from pg_stat_activity;
    
    # 查询最大连接数
    show max_connections;
    
  • MySQL给已存在的主键字段添加自增AUTO_INCREMENT

    每次都记不起来,记录一下…

    # 添加自增约束
    alter table table_name modify column COLUMN_NAME COLUMN_TYPE auto_increment;
    # 配置自增起始值
    alter table table_name auto_increment=10000;
    
  • PHP中对象缓存方式的选择

    类似于Map的键值类型对象缓存对于提高应用的性能有很大的作用,实现此类缓存的方式也比较多,那么该如何选择对象缓存的方式呢?由于PHP常用的运行方式主要是基于FPM的形式,这篇文章暂不考虑常驻内存形式的缓存。

    一、基于文件系统实现缓存

    这应该是比较常见的一种形式,基于文件系统的缓存优点:

    • 不需要安装额外的扩展、中间件
    • 支持几乎所有运行环境
    • 支持文件锁

    缺点:

    • 相对内存形式的缓存方式,性能一般
    • 存在并发读写时,性能极差(并发写,使用文件锁的情况)
    • 占用磁盘容量
    • 不好统计键调用次数等

    适合的场景:单机运行,单键极少写请求,需要持久化的情况,比如动态页面的静态化。

    二、基于数据库实现缓存

    优点:

    • 支持几乎所有运行环境,仅需要安装对应数据库的驱动程序,大部分环境默认提供至少一种数据库驱动程序
    • 支持锁
    • 方便进行复杂的查询统计

    缺点:

    • 作为最常遇到的性能问题点,不太适合用于缓存场景
    • 读写性能一般

    适合的场景:无法控制宿主安装程序或者扩展。

    三、基于Redis/Memcached等中间件实现缓存

    优点:

    • 读写性能好
    • 支持集群运行
    • 支持多数据结构(Redis)
    • 本身支持缓存淘汰策略

    缺点:

    • 需要额外的中间件
    • 需要额外的扩展、包支持
    • 大多数主机环境不支持(可喜的是随着公有云的发展,主机环境正在被新的虚拟化方式替代)

    适合的场景:只要支持安装,适合绝大多数场景。

  • 好用的自托管应用

    1. WordPress

    几乎是博客/电商独立站首选,或许不是那么完美,生态肯定是最完善的。

    2. Nextcloud

    开源网盘,官方客户端同步功能很好用,提供webdav访问,可以搭配其他支持webdav的应用使用。

    3. VaultWarden

    基于RUST的开源BitWarden服务端实现,用于存储密码/密钥/MFA/FIDO等信息。

    4. Code Server

    开源在线VScode编辑器。

    5. Redis Insight

    redis管理工具

    6. CloudBeaver

    开源在线数据库管理工具

    7. Parse Platform

    开源支持多平台的BAAS服务。

  • APP分发前的准备工作

    1. 登录、注册、注销
    2. 隐私权政策和服务协议
    3. 登录注册页面弹窗(勾选已读服务协议和隐私权政策,弹窗动作必须)
    4. 应用市场和对应账号
      • 苹果开发者会员
      • 主体认证
      • 涉及收费可能需要ICP证
    5. 软著登记证
  • APP Store应用上架需要注意的点

    最近公司的应用上架APP Store过程中一直遇到审核问题,记录一下遇到的问题,方便后续其他应用开发避坑。

    1、与安卓通用的审核条件

    APP分发前的准备工作

    2、虚拟支付

    – 所有的虚拟商品直接使用苹果的内购方式付款,避免后续改造的问题(需要给苹果30%抽成)
    – 提前考虑宣传物料和价格在不同货币区域的展示,或者避免物料中包含价格
    – 至少审核阶段,不要在应用界面里放跳转到其他应用的链接,苹果审核会认为这涉及到其他支付方式

    3、强制登录问题

    微信小程序也是一样的要求,所以最好设计阶段就开始考虑这个问题。

    – 不需要用户信息的数据不设计为强制鉴权
    – 将引导用户登录放到用户进行必须鉴权的操作时

  • Debian配置自动清理Journal日志

    Debian系统上(红帽系Linux发行版应该也是一样的),systemd-journald 服务负责管理 journal 日志。这些日志可以占用大量的磁盘空间,特别是当系统持续运行并且产生大量日志条目时。可以配置 systemd-journald 的日志保留策略来自动清理这些日志。

    1. 编辑 systemd-journald 的配置文件

    systemd-journald 的主要配置文件是 /etc/systemd/journald.conf

    sudo vim /etc/systemd/journald.conf
    

    2. 配置日志保留策略

    在配置文件中,你可以设置以下选项来控制日志的保留:

    • SystemMaxUse=: 设置系统日志可使用的最大磁盘空间。例如,SystemMaxUse=50M 会限制系统日志使用最多50MB的磁盘空间。
    • SystemKeepFree=: 设置保留的空闲磁盘空间。例如,SystemKeepFree=1G 会确保至少有1GB的空闲磁盘空间不会被日志使用。
    • MaxRetentionSec=: 设置日志条目的最大保留时间。例如,MaxRetentionSec=1month 会自动删除超过一个月的日志条目。

    3. 重新加载配置并重启服务

    在修改配置文件后,你需要重新加载 systemd 的配置并重启 systemd-journald 服务。

    sudo systemctl daemon-reload
    
    sudo systemctl restart systemd-journald
    

    4. 检查配置是否生效

    使用 journalctl 命令来检查 journal 的当前状态和配置。

    journalctl --disk-usage # 查看当前占用空间
    
    journalctl --vacuum-size=50M  # 可以用这个命令手动清理日志到指定大小,但通常不需要这样做,因为自动清理应该已经配置好了。
    

    5. 监控磁盘使用情况

    为了确保你的日志清理策略按预期工作,建议定期监控服务器的磁盘使用情况。你可以使用 df 命令来检查磁盘空间的使用情况。

    6. 注意事项

    • 在修改任何系统配置文件之前,最好先备份原始文件。
    • systemd-journald 的日志清理策略是基于磁盘空间使用量或日志条目的保留时间来工作的,所以确保你设置的策略符合你的实际需求。
    • 如果你的系统上有大量的日志生成,并且磁盘空间有限,你可能还需要考虑其他日志管理策略,如将日志发送到远程日志服务器或定期归档旧日志。
  • 使用Docker Compose部署NextCloud和WordPress

    一、全局配置

    name: lnmp
    services:
      caddy:
        image: caddy:latest
        volumes:
          - ./www:/var/www/html
          - ./caddy/etc:/etc/caddy
          - ./caddy/data:/data
          - ./caddy/config:/config
        ports:
          - 80:80
          - 443:443/tcp
          - 443:443/udp
        logging:
          driver: "json-file"
          options:
            max-size: "10m"
            max-file: 3
        restart: always
    
      redis:
        image: redis:latest
        volumes:
          - ./redis/config:/etc/redis
          - ./redis/data:/data
        restart: always
        command: /etc/redis/redis.conf
    
      mysql:
        image: mysql:latest
        volumes:
          - ./mysql/config:/etc/mysql
          - ./mysql/data:/var/lib/mysql
          - ./mysql/mysql-files:/var/lib/mysql-files
        cap_add:
          - SYS_NICE
        security_opt:
          - seccomp:unconfined
        environment:
          MYSQL_ROOT_PASSWORD: password
        ports:
          - 3306:3306
        restart: always
    
      php:
        build: ./php
        volumes:
          - ./php/config:/usr/local/etc
          - ./php/logs:/var/log/php
          - ./www:/var/www/html
        depends_on:
          - caddy
          - mysql
          - redis
        cap_add:
          - SYS_PTRACE
        logging:
          driver: "json-file"
          options:
            max-size: "10m"
            max-file: 3
        restart: always
    
      imaginary:
        image: nextcloud/aio-imaginary:latest
        restart: always
        command: -concurrency 2 -enable-url-source
        environment:
          - PORT=9000
    

    1. PHP

    PHP官方的镜像启用和安装的扩展比较少,直接使用会导致WordPress和Nextcloud的健康检查一堆信息,所以使用Dockerfile来基于官方镜像构建一个专用的镜像,PHP需要的扩展包括:

    • gd(png/jpeg/gif/webp/avif)
    • imagick
    • opcache(考虑性能)
    • apcu(Nextcloud的本地缓存)
    • zip(影响WordPress插件安装)
    • redis(WordPress的对象缓存和Nextcloud的分布式缓存)
    • gmp
    • intl
    FROM registry.cn-beijing.aliyuncs.com/ianzhi/php:8.4-fpm-alpine
    
    # 配置国内镜像
    RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
    
    # 安装构建扩展相关依赖
    RUN apk add --no-cache --update --virtual .build-deps $PHPIZE_DEPS
    
    # MySQL
    RUN docker-php-ext-install pdo_mysql mysqli \
      && docker-php-ext-enable pdo_mysql mysqli
    
    # 常用扩展
    RUN docker-php-ext-install pcntl exif bcmath sysvsem \
        && docker-php-ext-enable opcache exif bcmath pcntl sysvsem
    
    # apcu
    RUN pecl install apcu && docker-php-ext-enable apcu
    
    # zip扩展
    RUN apk add --no-cache --update libzip=1.11.4-r0 libzip-dev=1.11.4-r0 unzip \
      && docker-php-ext-install zip \
      && docker-php-ext-enable zip
    
    # redis
    RUN pecl install https://pecl.php.net/get/redis-6.2.0.tgz \
      && docker-php-ext-enable redis
    
    # intl
    RUN apk add --no-cache --update icu icu-dev \
      && docker-php-ext-configure intl \
      && docker-php-ext-install intl \
      && docker-php-ext-enable intl
    
    # imagick
    RUN apk add --no-cache --update imagemagick-dev imagemagick-svg \
     && pecl install https://pecl.php.net/get/imagick-3.8.0.tgz \
     && docker-php-ext-enable imagick
    
    # gd
    RUN apk add --no-cache --update libpng libpng-dev libavif-dev libjpeg-turbo-dev freetype-dev freetype libjpeg-turbo libavif  \
      && docker-php-ext-configure gd --with-freetype --with-jpeg --with-avif \
      && docker-php-ext-install gd \
      && docker-php-ext-enable gd
    
    # ffmpeg nextcloud需要视频转码时启用
    # RUN apk add --no-cache ffmpeg
    
    # gmp nextcloud使用加密时使用
    # RUN apk add --no-cache --update gmp-dev \
    # && docker-php-ext-install gmp \
    # && docker-php-ext-enable gmp
    
    # pgsql
    # RUN apk add --no-cache --update libpq-dev postgresql-dev \
    #   && docker-php-ext-install pdo_pgsql \
    #   && docker-php-ext-enable pdo_pgsql
    
    # 删除构建依赖
    RUN apk del --no-network .build-deps
    
    # 配置文件
    RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini
    
  • 使用微信小程序来实现扫码登录网站

    微信小程序本身提供了openid等信息的无感知获取,基于此来实现微信扫码登录,主要包含以下几个步骤:

    1. WEB登陆页面的实现

    打开登录页面时,生成一个带有唯一ID的小程序码,小程序码图片加载以后,通过WebSocket或者轮询确认此唯一ID是否已经确认登陆或者超时。

    这一步比较简单,进入登录页面,通过调用生成小程序码接口,就可以生成一个带有特定参数的小程序码。

    通过图片的onload的属性,可以启动一个定时器或者WebSocket连接到后端,获取是否已经确认登陆或者超时过期。

    2. 微信小程序端的实现

    通过onLoad可以获取到携带的唯一ID,调用login接口后可以获取code,合并到一起提交到后端登陆接口,后端可以通过调用code获取到session信息,用以区分不同用户。

    查询到用户以后,将对应的用户标记为登陆状态即可,具体实现可以按照应用逻辑来。

    3. 后端的实现

    后端主要包括:

    1. 小程序码接口,用于展示小程序码图片
    2. 登录接口,接受code和唯一ID
    3. 状态查询接口,或者WebSocket服务,用于前端查询或者推送唯一ID过期或者确认登陆状态,实现登陆后的跳转。
  • Linux服务器的安全相关配置

    记录一下Linux服务器一般常用的安全相关配置,避免被简单的黑掉,更复杂的配置暂不考虑深入研究了。

    1. 添加用户、用户组

    # 添加用户组
    groupadd users
    # 添加用户
    useradd test
    # 将用户test添加到users组中
    usermod -g users test
    

    2. 启用密钥登陆

    # 1. 开启密钥登陆配置
    vim /etc/ssh/sshd_config
    
    # 将一下两个配置项打开
    RSAAuthentication yes
    PubkeyAuthentication yes
    
    # 2. 配置密钥
    # 生成密钥
    ssh-keygen
    # 复制公钥,放进服务器/home/xxx/.ssh/authorized_keys文件中
    vim /home/xxx/.ssh/authorized_keys
    
    # 3. 使用公钥测试连接
    ssh test@1.1.1.1
    
    # 4. 关闭密码登陆功能
    vim /etc/ssh/sshd_config
    
    # 禁止使用密码登陆
    PasswordAuthentication no
    # 禁止root账号登陆
    PermitRootLogin no
    # 指定SSH协议版本
    Protocol 2
    # 最大尝试次数
    MaxAuthTries 3
    
    # 重启ssh服务
    systemctl restart sshd
    
    # 5. 配置仅允许指定组使用su
    vi /etc/pam.d/su
    
    # 添加行
    auth required pam_wheel.so group=xxx
    
    # 6. 启用防火墙
    # Debian防火墙默认允许所有INPUT和OUTPUT,
    # 建议直接关闭所有流入,然后根据需要配置开放的端口,比如80,443,22等
    # 除了80与443,建议其他程序都更换默认端口,每增加一个策略就会增加部分安全性
    # !!!!禁止所有流量流入,注意放开SSH,否则就进不去了!!!!
    systemctl start nftables
    systemctl enable nftables
    
  • 如何将网站权重提升到1

    在Google中,网站的权重(或者说“PageRank”)是一个页面的重要性的度量。它基于链接,也就是其他页面指向该页面的链接。当搜索引擎(比如Google)找到一个页面时,它会对该页面进行评估,并根据该页面的链接数量和质量来决定其权重。权重高的页面通常会在搜索结果中排名更高。

    为了提高网站的权重,你可以采取以下一些步骤:

    1. 创建高质量的内容。搜索引擎喜欢有价值的内容,所以如果你能提供独特、有用的内容,他们会更容易将你的页面排在搜索结果的前面。
    2. 获得更多的链接。如果其他网站指向你的页面,搜索引擎就会认为你的页面更重要。你可以通过以下方式获得更多链接: * 在其他网站上发布文章。如果你的文章被其他网站引用,搜索引擎就会将这些链接计入你的权重。 * 交换链接。如果你与其他网站的站长协商,让他们在自己的网站上链接到你的页面,你们两个的权重都会提高。 * 使用链接诱饵。如果你能提供有趣、有用的内容作为诱饵,吸引其他网站的站长链接到你的页面,搜索引擎也会将这些链接计入你的权重。
    3. 提高页面的排名。搜索引擎使用算法来对网站进行排名。你可以通过优化这些算法来提高自己的页面排名。例如,使用关键词作为标题和描述,让搜索引擎更容易理解你的页面内容。
    4. 不断更新网站。搜索引擎喜欢不断更新的网站。所以如果你能定期更新网站上的内容,就有助于提高权重。

    这些方法可能需要一些时间才能显现出效果。通常来说,新的网站需要几个月的时间才能提高权重,而更老的网站则可能需要更长的时间。但是如果你能坚持不懈地进行优化,最终你的网站权重就有可能提高到1,也就是最高级别。

  • HTTP status and The meaning

    Here are some of the most common HTTP status codes and their meanings:

    • 1xx – Informational: These status codes indicate that the request has been received and is being processed.
      • 100 Continue: The server has received the request headers and is waiting for the request body.
      • 101 Switching Protocols: The server has switched to a different protocol, such as HTTP/2.
    • 2xx – Success: These status codes indicate that the request has been successfully received, understood, and accepted.
      • 200 OK: The request has been successfully completed.
      • 201 Created: The request has been fulfilled and a new resource has been created.
      • 202 Accepted: The request has been accepted for processing, but the processing has not been completed yet.
    • 3xx – Redirection: These status codes indicate that further action needs to be taken in order to complete the request.
      • 301 Moved Permanently: The requested resource has been moved permanently to a new location.
      • 302 Found: The requested resource has been temporarily moved to a new location.
      • 304 Not Modified: The requested resource has not been modified since the last time it was requested.
    • 4xx – Client Error: These status codes indicate that the request contains bad syntax or cannot be fulfilled.
      • 400 Bad Request: The request cannot be understood by the server.
      • 401 Unauthorized: The request requires authentication.
      • 404 Not Found: The requested resource could not be found.
    • 5xx – Server Error: These status codes indicate that the server has encountered an error while processing the request.
      • 500 Internal Server Error: An unexpected error has occurred on the server.
      • 503 Service Unavailable: The server is temporarily unavailable.
      • 504 Gateway Timeout: The server did not receive a timely response from another server.

    There are many other HTTP status codes, but these are some of the most common ones. You can find a complete list of HTTP status codes here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status

  • SEO如何优化网站标题

    网站标题是SEO优化中非常重要的一部分,以下是一些可以优化网站标题的建议:

    1. 确保网站标题是简短、明了和有吸引力的,以吸引更多的用户点击访问。
    2. 将网站标题中的关键词进行合理的排列,以提高网站在搜索引擎中的排名。
    3. 将网站标题中的关键词进行加粗或标记,以提高关键词的可见性和重要性。
    4. 使用H标签来突出显示网站标题,以提高用户体验和SEO效果。
    5. 定期更新网站标题,以反映网站内容和主题的变化,以吸引更多的用户点击访问。
    6. 使用网站分析工具来监控和优化网站的性能,以确保网站标题能够被正确地处理和索引。

    需要注意的是,网站标题的优化需要结合整个SEO优化策略来进行,以达到最好的效果。

  • WordPress常用插件

    WordPress提供了完善的插件机制,通过使用插件,我们可以优化Wordpress的性能、丰富Wordpress的功能,但是插件市场的插件实现也良莠不齐的,记录一些使用体验优秀的插件。

    一、性能优化插件

    1. Performance Lab

    WordPress性能团队提供的一些独立性能优化插件,是一个插件组合,包含了一系列可以优化WordPress站点性能的插件,包括但不限于:

    • 推测性加载
    • 现代图片格式支持
    • 翻译性能优化
    • web worker
    • 视图过渡动效

    Performance plugin from the WordPress Performance Team, which is a collection of standalone performance modules.

    2. Redis Object Cache

    WordPress的对象缓存插件。

    A persistent object cache backend powered by Redis. Supports Predis, PhpRedis, Relay, replication, sentinels, clustering and WP-CLI.

    3. Super Cache

    WordPress官方提供的快速缓存插件,支持CDN、预缓存以及cache-control相关功能等。

    4. Simple Cloudflare Turnstile

    这个是在登录页面增加一个Cloudflare验证码,避免一些尝试暴力破解登录密码的脚本。

    Easily add Cloudflare Turnstile to all your WordPress website forms to protect them from spam!

    A user-friendly, privacy-preserving reCAPTCHA alternative.

    二、REST API插件

    1. JWT Auth

    提供REST API的JWT认证,没有管理界面。

    三、功能插件

    1. woocommerce

    一站式帮助您在数天内推出一个在线商店并保持持续发展。 从您的第一笔交易到赚得数百万收入,Woo 都与您同在。

    2. Action Scheduler

    A robust scheduling library for use in WordPress plugins.

    3. Two-Factor

    通过“用户”→“个人资料”下的“双重身份验证选项”部分,为您的账户启用和配置一个或多个双重身份验证方式:

    • 邮件验证码
    • 基于时间的一次性密码(TOTP)
    • FIDO 通用第二因素(U2F)
    • 备用验证码
    • 虚拟方式(仅用于测试目的)

    4. 安全自定义字段

    安全自定义字段(SCF)扩展了 WordPress 的权限,将其转化为灵活的内容管理工具。有了 SCF,管理自定义数据变得简单而高效。

    按需轻松创建字段。 SCF 生成器可以轻松地将字段添加到 WordPress 编辑屏幕,无论您是为菜谱添加新的「成分」字段,还是为专业网站设计复杂的元数据。

    **灵活放置。**字段可应用于整个 WordPress–文章、页面、用户、分类法、媒体、评论,甚至自定义选项页面–按照您的意愿组织数据。

    **无缝显示。**使用 SCF 功能,您可以在模板中显示自定义字段数据,使所有级别的开发人员都能轻松实现内容集成。

    **全面的内容管理解决方案。**除自定义字段外,SCF 还允许您直接从 SCF 界面注册新的文章类型和分类法,从而提供更多控制,而无需额外的插件或自定义代码。

    **易于访问和用户友好的设计。**字段界面与 WordPress 的本地设计保持一致,为内容创建者创造了一种易于访问和使用的体验。

  • How to calculate the similarity of two articles using PHP

    How to calculate the similarity of two articles using PHP?

    • Using the similar_text() function: This is a built-in function in PHP that calculates the similarity of two strings. It returns the number of matching characters in the two strings, or the similarity in percent if the third parameter is passed.

    PHP

    $similarity = similar_text($article1, $article2);
    
    if ($similarity > 0.75) {
      echo "The two articles are very similar.";
    } else {
      echo "The two articles are not very similar.";
    }
    

    Use code with caution. Learn morecontent_copy

    • Using the levenshtein() function: This is another built-in function in PHP that calculates the Levenshtein distance between two strings. The Levenshtein distance is a measure of how similar two strings are, and it is calculated by counting the number of edits (insertions, deletions, or substitutions) required to transform one string into the other.

    PHP

    $levenshtein_distance = levenshtein($article1, $article2);
    
    if ($levenshtein_distance < 10) {
      echo "The two articles are very similar.";
    } else {
      echo "The two articles are not very similar.";
    }
    

    Use code with caution. Learn morecontent_copy

    • Using a custom algorithm: You can also write your own custom algorithm to calculate the similarity of two articles. This could involve using a variety of factors, such as the number of common words, the number of common phrases, the order of the words, and the grammatical structure of the articles.

    Once you have calculated the similarity of two articles, you can use it to do a variety of things, such as:

    • Detecting plagiarism: You can use the similarity of two articles to detect plagiarism. If the similarity is high, then it is likely that one of the articles is a plagiarized version of the other.
    • Recommending similar articles: You can use the similarity of two articles to recommend similar articles to users. For example, if a user reads an article about “how to cook a steak,” you could recommend other articles about “how to cook a chicken” or “how to cook a fish.”
    • Clustering articles: You can use the similarity of two articles to cluster articles together. This could be useful for organizing articles in a database or for creating a search engine.

    I hope this helps!

  • how to improve the rank of search results in google

    There are many factors that affect a website’s ranking in Google search results, but some of the most important include:

    • Content: Your website’s content should be high-quality, informative, and relevant to the keywords you are targeting.
    • Keywords: You should use keywords throughout your website’s content, but in a natural way. Avoid keyword stuffing, which can actually hurt your rankings.
    • Backlinks: Backlinks are links from other websites to yours. The more backlinks you have from high-quality websites, the better your rankings will be.
    • Technical SEO: Your website’s technical SEO should be sound. This includes factors such as page speed, mobile-friendliness, and security.
    • User experience: Google also considers user experience when ranking websites. This means that your website should be easy to use and navigate.

    Here are some specific steps you can take to improve your website’s ranking in Google search results:

    1. Do keyword research: Identify the keywords that people are using to search for the products or services you offer.
    2. Create high-quality content: Write content that is informative, relevant, and well-written. Use your target keywords throughout your content, but in a natural way.
    3. Optimize your website for search engines: Use the right keywords in your website’s title tags, meta descriptions, and other on-page elements.
    4. Build backlinks: Get backlinks from other high-quality websites. This will help to improve your website’s authority and ranking.
    5. Fix any technical SEO issues: Make sure your website is mobile-friendly, secure, and loads quickly.
    6. Monitor your results: Use Google Search Console to track your website’s ranking and make adjustments as needed.

    Improving your website’s ranking in Google search results takes time and effort, but it is worth it. By following the tips above, you can improve your chances of ranking higher in search results and attracting more visitors to your website.

    Here are some additional tips that may help you improve your search ranking:

    • Use long-tail keywords: Long-tail keywords are more specific than short-tail keywords, and they are often easier to rank for.
    • Create fresh content: Google favors websites that are updated regularly. Make sure you are adding new content to your website on a regular basis.
    • Promote your website: Share your website’s content on social media and other online channels. This will help to increase your website’s visibility and improve your ranking.

    I hope this helps!