欢迎来到 艾瑞可erik 的魔法世界 🧙‍♂️

给我一个需求,还你一个项目——别管它是什么。这就是全栈。

📚 291 篇文章 🏷️ 504 个标签 📂 90 个分类

🔥 最新文章

内网穿透、支付接口本地化开发、本地挂网外网访问

在技术qq群偶然聊得最近想入手一台微型服务器,电脑装虚拟机多了感觉好卡,操作不太方便。 群友有提到利用内网穿透不必本地挂载linux服务器便可以很轻松实现。

顺便就查查他们所说的ngrok,百度的解释如下:

看来这是个不错的工具,减少挂载带来的资源占用。

Intranet Penetration, Localized Payment Interface Development, and Hosting Locally with External Access

Chatting casually in a technical QQ group, I mentioned that I’d recently been thinking about getting a mini server, since running too many virtual machines on the computer feels slow and is inconvenient to operate. A group member mentioned that with intranet penetration you can do it very easily without hosting a Linux server locally.

So I looked up the ngrok they were talking about. Baidu’s explanation is as follows:

Looks like this is a pretty good tool — it reduces the resource usage that comes with hosting.

php对接微信支付问题

官方文档比较简略,demo教程基本没参数注释,看代码找吧。
支付 扫码支付 native.php
模式二

$input->SetBody(“test”); //描述

$input->SetAttach(“test”); //订单id 附件自定义数据,会会原样返回

$input->SetGoods_tag(“test”); //代金券或立减优惠功能的参数

$input->SetNotify_url(‘url’); //指定回调地址

$input->SetProduct_id(‘test’); //商户订单号 如果用模式一就要去微信公众平台配置回调地址 ,模式二就不用配置

Problems integrating WeChat Pay with PHP

The official documentation is fairly brief, the demo tutorial basically has no parameter comments, so just read the code and figure it out.
Payment Scan-code payment native.php
Mode 2

$input->SetBody(“test”); //description

$input->SetAttach(“test”); //order id, attachment custom data, which will be returned as-is

$input->SetGoods_tag(“test”); //parameters of the voucher or instant discount feature

$input->SetNotify_url(‘url’); //specify the callback address

$input->SetProduct_id(‘test’); //merchant order number. If you use Mode 1 you have to go configure the callback address on the WeChat official platform; Mode 2 does not need configuration

php中单元测试安装phpunit(win+linux)

要获取 PHPUnit,最简单的方法是下载 PHPUnit 的 PHP 档案包 (PHAR),它将 PHPUnit 所需要的所有必要组件(以及某些可选组件)捆绑在单个文件中:

要使用 PHP档案包(PHAR)需要有 phar 扩展。

要使用 PHAR 的 —self-update 功能需要有 openssl 扩展。

如果启用了 Suhosin 扩展,需要在 php.ini 中允许执行 PHAR:

suhosin.executor.include.whitelist = phar

如果要全局安装 PHAR:

$ wget https://phar.phpunit.de/phpunit.phar
$ chmod +x phpunit.phar
$ sudo mv phpunit.phar /usr/local/bin/phpunit
$ phpunit --version
PHPUnit x.y.z by Sebastian Bergmann and contributors.

也可以直接使用下载的 PHAR 文件:

$ wget https://phar.phpunit.de/phpunit.phar
$ php phpunit.phar --version
PHPUnit x.y.z by Sebastian Bergmann and contributors.

Windows

整体上说,在 Windows 下安装 PHAR 和手工在 Windows 下安装 Composer 是一样的过程:
  1. 为 PHP 的二进制可执行文件建立一个目录,例如 C:\bin
  2. 将 ;C:\bin 附加到 PATH 环境变量中(相关帮助)
  3. 下载 https://phar.phpunit.de/phpunit.phar 并将文件保存到 C:\bin\phpunit.phar
  4. 打开命令行(例如,按 Windows+R » 输入 cmd » ENTER)
  5. 建立外包覆批处理脚本(最后得到 C:\bin\phpunit.cmd):
    C:\Users\username>cd C:\binC:\bin>echo @php "%~dp0phpunit.phar" %* > phpunit.cmdC:\bin>exit
  6. 新开一个命令行窗口,确认一下可以在任意路径下执行 PHPUnit:
    C:\Users\username>phpunit --versionPHPUnit x.y.z by Sebastian Bergmann and contributors.
phpunit官方中文手册 https://phpunit.de/manual/current/zh_cn/installation.html
下载地址:https://phar.phpunit.de/

Installing PHPUnit for Unit Testing in PHP (win+linux)

The simplest way to get PHPUnit is to download PHPUnit’s PHP Archive (PHAR), which bundles all the necessary components PHPUnit needs (plus some optional ones) into a single file:

To use the PHP Archive (PHAR) you need the phar extension.

To use PHAR’s —self-update feature you need the openssl extension.

If the Suhosin extension is enabled, you need to allow PHAR execution in php.ini:

suhosin.executor.include.whitelist = phar

To install PHAR globally:

$ wget https://phar.phpunit.de/phpunit.phar
$ chmod +x phpunit.phar
$ sudo mv phpunit.phar /usr/local/bin/phpunit
$ phpunit --version
PHPUnit x.y.z by Sebastian Bergmann and contributors.

You can also just use the downloaded PHAR file directly:

$ wget https://phar.phpunit.de/phpunit.phar
$ php phpunit.phar --version
PHPUnit x.y.z by Sebastian Bergmann and contributors.

Windows

Overall, installing PHAR on Windows is the same process as manually installing Composer on Windows:
  1. Create a directory for PHP's binary executable, for example C:\bin
  2. Append ;C:\bin to the PATH environment variable (related help)
  3. Download https://phar.phpunit.de/phpunit.phar and save the file to C:\bin\phpunit.phar
  4. Open a command line (for example, press Windows+R » type cmd » ENTER)
  5. Create an outer wrapper batch script (you end up with C:\bin\phpunit.cmd):
    C:\Users\username>cd C:\binC:\bin>echo @php "%~dp0phpunit.phar" %* > phpunit.cmdC:\bin>exit
  6. Open a new command line window and confirm that you can run PHPUnit from any path:
    C:\Users\username>phpunit --versionPHPUnit x.y.z by Sebastian Bergmann and contributors.
PHPUnit official Chinese manual https://phpunit.de/manual/current/zh_cn/installation.html
Download address: https://phar.phpunit.de/

hadoop2.8.0的部署安装教程

Hadoop部署准备 本地vmware安装 Linux系统家族中 centos7 下载地址http://101.110.118.58/isoredirect.centos.org/centos/7/isos/x86\_64/CentOS-7-x86\_64-Minimal-1611.iso Java对应版本1.8.0_121 Hadoop版本2.8.0下载地址 http://mirror.bit.edu.cn/apache/hadoop/common/ 可以根据自己喜好的版本下载

1.基本配置

首先安装一个centos7并配置好java Java环境配置 我的java安装地址 /usr/java/ jdk1.8.0_121 编辑java环境 vi ~/.bash_profile 添加或修改 export JAVA_HOME=/usr/java/jdk1.8.0_121 export PATH=$JAVA_HOME/bin:$PATH 执行 . ~/.bash_profile 使变量生效

Hadoop 2.8.0 Deployment and Installation Tutorial

Hadoop deployment preparation: install Linux locally under VMware. In the Linux family, the CentOS 7 download address is http://101.110.118.58/isoredirect.centos.org/centos/7/isos/x86\_64/CentOS-7-x86\_64-Minimal-1611.iso The matching Java version is 1.8.0_121 Hadoop version 2.8.0 download address http://mirror.bit.edu.cn/apache/hadoop/common/ you can download whichever version you like

1. Basic configuration

First install a CentOS 7 and get Java configured. Java environment configuration: my Java install location is /usr/java/ jdk1.8.0_121 edit the Java environment with vi ~/.bash_profile, add or modify export JAVA_HOME=/usr/java/jdk1.8.0_121 export PATH=$JAVA_HOME/bin:$PATH then run . ~/.bash_profile to make the variables take effect

PHP数组、函数、字符串的常识

php数组排序

sort()根据数组所包含元素进行升序排列 sort()函数是区分大小写。

所有大写字母都在小写字母后面。

asort()函数和ksort()函数对关联数组排序

例如:$a=array(‘name’=>100,’user’=>200,’title’=>300);

函数asort()是根据数组$a的每个元素值进行排序。在数组$a中元素值为数字。

PHP Basics: Arrays, Functions, and Strings

Sorting PHP arrays

sort() sorts the elements contained in the array in ascending order; the sort() function is case-sensitive.

All uppercase letters come after lowercase letters.

The asort() function and the ksort() function sort associative arrays

For example: $a=array(‘name’=>100,’user’=>200,’title’=>300);

The asort() function sorts by each element value in the array $a. In the array $a the element values are numbers.

PHP算法和递归

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php 
header("Content-Type:text/html;charset=utf-8");

$arr=array(1,12,53,14,5,16,7,18,91,10,11,120); //**冒泡排序** 小数往前放,大数往后放

function getpao($arr) {

$len=count($arr); //设置一个空数组 用来接收冒出来的泡 //该层循环控制 需要冒泡的轮数

for($i=1;$i<$len;$i++) { //该层循环用来控制每轮 冒出一个数 需要比较的次数

for($k=0;$k<$len-$i;$k++) {

if($arr\[$k\]>$arr\[$k+1\]) {

$tmp=$arr\[$k+1\]; $arr\[$k+1\]=$arr\[$k\]; $arr\[$k\]=$tmp;

}

}

}

return $arr;

}

PHP algorithms and recursion

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php 
header("Content-Type:text/html;charset=utf-8");

$arr=array(1,12,53,14,5,16,7,18,91,10,11,120); //**Bubble sort** small numbers move to the front, large numbers move to the back

function getpao($arr) {

$len=count($arr); //set up an empty array to receive the bubbles that come up //this loop layer controls how many rounds of bubbling are needed

for($i=1;$i<$len;$i++) { //this loop layer controls how many comparisons are needed for one number to bubble up each round

for($k=0;$k<$len-$i;$k++) {

if($arr\[$k\]>$arr\[$k+1\]) {

$tmp=$arr\[$k+1\]; $arr\[$k+1\]=$arr\[$k\]; $arr\[$k\]=$tmp;

}

}

}

return $arr;

}

mysql如何应对消息

在使用mysql数据库时,如果是商城那就要考虑到秒杀、抢购、发消息等同一时间访问数据库所带来的堵塞从而压垮数据库。 如何有效的在程序和mysql是做些处理来应对呢。

答案就是:把http请求放入内存的高速队列,然后对队列里的数据按一定的规则进行分流处理。 当一个用户发送一个请求时,我们可以给他延迟2s,依次类推。

如果是发送通知类消息,用户量大,不可能同时发送,那么就是需要列队发送;把发送的消息操作延迟,同时针对活跃用户 优先发送(即异步操作),合理分摊服务器负担。

异步操作优点:部署简单,使用mysql内置存储过程和定时器即可完成大部分调度,服务器部署简单,容易迁移。

缺点:对于大数据量、上千万的消息处理效果不佳。不能应对实时性要求很高的场所。 关于htpp队列,金山有个内部开源HTTPSQL,把队列从mysql移到内存数据库中,并有一个专门的进程负责队列的操作,客户端则通过socket请求进行读写。 另外还有一个轻量级的基于内存的消息队列ZeroMQ,此队列是通过API来实现消息的传输。

How MySQL handles messages

When using a MySQL database, if it’s a shopping site you have to take into account flash sales, panic buying, message sending and other cases where simultaneous access to the database causes congestion and ends up crushing the database. How can we effectively do some handling in the program and in MySQL to cope with it?

The answer is: put the HTTP requests into a high-speed in-memory queue, then split and process the data in the queue according to certain rules. When a user sends a request, we can delay it by 2s for that user, and so on.

If you are sending notification-type messages, the user base is large and you can’t send them all at once, so you need to queue them up for sending; delay the message-sending operations while giving priority to active users (that is, asynchronous operations), reasonably spreading the load on the server.

Advantages of asynchronous operations: simple deployment — most scheduling can be done with MySQL’s built-in stored procedures and timers — and the server deployment is simple and easy to migrate.

Disadvantages: it doesn’t work well for large data volumes or for handling tens of millions of messages. It cannot cope with scenarios that demand very high real-time performance. As for HTTP queues, Kingsoft has an internally open-sourced HTTPSQL that moves the queue out of MySQL and into an in-memory database, with a dedicated process responsible for queue operations while clients read and write through socket requests. There is also a lightweight in-memory message queue, ZeroMQ, which transfers messages through its API.

mysql瓶颈的应对措施

mysql本身是存在瓶颈的,当数据量达到千万级别以上,无论mysql如何优化,其性能都显著降低(有专门团队开发并改进mysql的除外)。 那么就有以下几种办法解决。
1.增加mysql配置中buffer和cache的数值,增加服务器cpu数量和内存大小。
2.使用第三方引擎或衍生版本。例如:Percona、MariaDB、TokuDB 3.迁移到其他数据库。例如:PostgreSQL、Oracle

How to Deal with MySQL Bottlenecks

mysql itself has bottlenecks: once the data volume reaches the tens-of-millions level or above, no matter how you optimize mysql, its performance drops noticeably (unless you have a dedicated team developing and improving mysql). So here are a few ways to solve it.

  1. Increase the buffer and cache values in the mysql configuration, and add more server CPUs and memory.
  2. Use a third-party engine or a derivative version. For example: Percona, MariaDB, TokuDB 3. Migrate to another database. For example: PostgreSQL, Oracle