PHP 多版本共存 PHP5.6 PHP7.2

先安装 php7,正常安装

php7.2 安装完成后,进行 php5.6 的安装

安装 php5

[root@VM_0_2_centos ~]# cd ~
[root@VM_0_2_centos ~]# wget -c http://cn2.php.net/distributions/php-5.6.30.tar.gz
[root@VM_0_2_centos ~]# tar -zxvf php-5.6.30.tar.gz
[root@VM_0_2_centos ~]# cd php-5.6.30/
[root@VM_0_2_centos php-5.6.30]# ./configure  --prefix=/usr/local/php5 --enable-fpm --with-mysql  --with-mysqli --with-zlib --with-curl --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-openssl --enable-mbstring --enable-xml --enable-session --enable-ftp --enable-pdo
[root@VM_0_2_centos php-5.6.30]# make

make 可能会报错:make: *** [sapi/cli/php] error 1 ,

则使用

[root@VM_0_2_centos php-5.6.30]# make clean
[root@VM_0_2_centos php-5.6.30]# make ZEND_EXTRA_LIBS='-liconv'

安装

[root@VM_0_2_centos php-5.6.30]# make install

复制 php 配置文件

[root@VM_0_2_centos php-5.6.30]# cp php.ini-production /usr/local/php5/etc/php.ini

已经安装完成,查看版本号

[root@VM_0_2_centos php-5.6.30]# /usr/local/php5/bin/php -v

返回

PHP 5.6.30 (cli) (built: Aug 29 2018 09:09:28) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

配置 php-fpm

[root@VM_0_2_centos php-5.6.30]# cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf
[root@VM_0_2_centos php-5.6.30]# vim /usr/local/php5/etc/php-fpm.conf

查找 user 将

user = nobody
group = nobody

改成

user = www
group = www

查找 listen 将

listen = 127.0.0.1:9000

改成

listen = 127.0.0.1:9001

配置 php-fpm 服务

[root@VM_0_2_centos php-5.6.30]# cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/php5-fpm.service
[root@VM_0_2_centos php-5.6.30]# vim /usr/lib/systemd/system/php5-fpm.service 

将:

PIDFile=${prefix}/var/run/php-fpm.pid
ExecStart=${exec_prefix}/sbin/php-fpm --nodaemonize --fpm-config ${prefix}/etc/php-fpm.conf

改成

PIDFile=/usr/local/php5/var/run/php-fpm.pid
ExecStart=/usr/local/php5/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php5/etc/php-fpm.conf

重新载入 systemd

[root@VM_0_2_centos php-5.6.30]# systemctl daemon-reload

可以设置开机启动:

[root@VM_0_2_centos php-5.6.30]# systemctl enable php5-fpm

返回结果

Created symlink from /etc/systemd/system/multi-user.target.wants/php5-fpm.service to /usr/lib/systemd/system/php5-fpm.service.

启动:

[root@VM_0_2_centos php-5.6.30]# systemctl start php5-fpm

关闭:

[root@VM_0_2_centos php-5.6.30]# systemctl stop php5-fpm

查看状态:

[root@VM_0_2_centos php-5.6.30]# systemctl status php5-fpm

返回

● php5-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php5-fpm.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2018-08-29 09:36:39 CST; 47s ago
 Main PID: 14996 (php-fpm)
   CGroup: /system.slice/php5-fpm.service
           ├─14996 php-fpm: master process (/usr/local/php5/etc/php-fpm.conf)
           ├─14997 php-fpm: pool www
           └─14998 php-fpm: pool www

配置不同的 nginx 站点使用不用的 PHP 版本

[root@VM_0_2_centos php-5.6.30]# cd /usr/local/nginx/conf/vhost/
[root@VM_0_2_centos vhost]# vim test.liuguofeng.com.conf 
server {
    listen       80;
    server_name  test.liuguofeng.com;
    root         /home/wwwroot/test.liuguofeng.com
    location / {
        index  index.php index.html index.htm;
    }
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9001;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

PHP 5 使用 9001 端口, PHP 7,使用 9000端口。

重载 nginx 服务

[root@lnmp conf.d]# systemctl reload nginx

访问 PHPINFO

PHP url 缺少 www 自动补全 www 函数

稍后继续优化

<?php
function addWww($url){
	$parse = parse_url($url);

	$scheme = isset($parse['scheme'])?$parse['scheme']:'';
	$host = isset($parse['host'])?$parse['host']:'';
	$path = isset($parse['path'])?$parse['path']:'';
	$query = isset($parse['query'])?$parse['query']:'';
	$fragment = isset($parse['fragment'])?$parse['fragment']:'';

	preg_match('/^(([www]{3})|([\w]{1,}))[\.][\w]*?[\.][com|cn|com.cn|cc|net]{2,}/',$host,$match);

	if($match){
		$resUrl = $url;
	}else{
		$resUrl = $scheme.'://'.'www.'.$host.$path.'?'.$query.'#'.$fragment;
	}
	return $resUrl;
}

微信分享 和 支付宝分享自动调用的设备使用情况

使用微信分享 和 支付宝分享时,微信服务器与阿里服务器自动调用网页情况记录

Linux; Android 8.0; ONEPLUS A3010 Build/OPR1.170623.032; 

iPhone; CPU iPhone OS 10_2_1 like Mac OS X

是本人设备

2018-08-24 14:48:54	http://wanai.unetu.net/	Mozilla/5.0 (Linux; Android 8.0; ONEPLUS A3010 Build/OPR1.170623.032; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/044205 Mobile Safari/537.36 MicroMessenger/6.7.2.1340(0x26070236) NetType/WIFI Language/zh_CN
2018-08-24 14:51:13	http://wanai.unetu.net/	Mozilla/5.0 (Linux; Android 8.0; ONEPLUS A3010 Build/OPR1.170623.032; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/044205 Mobile Safari/537.36 MicroMessenger/6.7.2.1340(0x26070236) NetType/WIFI Language/zh_CN
2018-08-24 14:54:10	/vip/relay_login?invited=&via=mobile	Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML; like Gecko) Mobile/12F70 MicroMessenger/6.1.5 NetType/WIFI
2018-08-24 14:54:10	/vip/relay_login?invited=&via=mobile	Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML; like Gecko) Mobile/12F70 MicroMessenger/6.1.5 NetType/WIFI
2018-08-24 14:54:11	/vip/relay_login?invited=&via=mobile	Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML; like Gecko) Mobile/12F70 MicroMessenger/6.1.5 NetType/WIFI
2018-08-24 14:54:24	http://wanai.unetu.net/vip/relay_login?invited=&via=mobile	Mozilla/5.0 (Linux; Android 8.0; ONEPLUS A3010 Build/OPR1.170623.032; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/044205 Mobile Safari/537.36 MicroMessenger/6.7.2.1340(0x26070236) NetType/WIFI Language/zh_CN
2018-08-24 14:55:24	http://wanai.unetu.net/vip/relay_info?invited=&via=none	Mozilla/5.0 (Linux; Android 4.4.4; Coolpad Y82-520 Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/33.0.0.0 Mobile Safari/537.36 MicroMessenger/6.5.4.1000 NetType/4G Language/zh_CN
2018-08-24 15:03:38	/vip/relay_login?invited=&via=none	Mozilla/5.0 (Linux; U; Android 8.0.0; zh-cn; ONEPLUS A3010 Build/OPR1.170623.032) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.0.0 Mobile Safari/537.36
2018-08-24 15:04:12	http://wanai.unetu.net/vip/relay_login?invited=&via=none	Mozilla/5.0 (Linux; U; Android 8.0.0; zh-cn; ONEPLUS A3010 Build/OPR1.170623.032) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.0.0 Mobile Safari/537.36
2018-08-24 15:05:01	http://wanai.unetu.net/branch/palipay_return/vip/0?body=3%E5%BC%A030%E5%85%83%E4%BB%A3%E9%87%91%E5%88%B8&is_success=T&notify_id=RqPnCoPT3K9%252Fvwbh3Ih134mxINV5jZfwxcrQKMegXWc3%252Bfdo4ugy5pN8E8Vf3iVhwW%252Fe&notify_time=2018-08-24+15%3A04%3A55&notify_type=trade_status_sync&out_trade_no=20180824-500001-150344_10095&payment_type=1&seller_id=2088911951177304&service=alipay.wap.create.direct.pay.by.user&subject=29%E5%85%83%E8%B4%AD%E4%B9%B0%E4%B8%87%E7%88%B1%E4%BB%A3%E9%87%91%E5%88%B8%E6%8E%A5%E9%BE%99&total_fee=0.02&trade_no=2018082422001417181000967030&trade_status=TRADE_SUCCESS&sign=JYCBvK68Vfol0lJpLH2ft5l59AirEw3dAWK8FBf4vJgrOR7Qpkv3AsgehR4iaujMSv6%2FJeYS5%2Bl7o2HVEbk42SE6cp9kXRrhQNmjPAPyZey8pQfROTKc9aG4BCuSjmaSYbBAxtz0XMqBPhZh3gFQt%2BcEw5IGEZIOPofk1pn6do0%3D&sign_type=RSA	Mozilla/5.0 (Linux; U; Android 8.0.0; zh-cn; ONEPLUS A3010 Build/OPR1.170623.032) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.0.0 Mobile Safari/537.36
2018-08-24 15:05:29	/vip/relay_login?invited=&via=pc	Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16A5364a MicroMessenger/6.7.2 NetType/WIFI Language/zh_CN
2018-08-24 15:05:54	http://wanai.unetu.net/vip/relay_login?invited=&via=pc	Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16A5364a MicroMessenger/6.7.2 NetType/WIFI Language/zh_CN
2018-08-24 15:06:30	http://wanai.unetu.net/vip/relay?via=pc	Mozilla/5.0 (iPhone; CPU iPhone OS 10_2_1 like Mac OS X) AppleWebKit/602.4.6 (KHTML, like Gecko) Mobile/14D27 MicroMessenger/6.5.5 NetType/WIFI Language/en
2018-08-24 15:06:56	http://wanai.unetu.net/vip/relay_info?invited=&via=none	Mozilla/5.0 (Linux; Android 4.4.4; HUAWEI ALE-CL00 Build/HuaweiALE-CL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.49 Mobile MQQBrowser/6.2 TBS/043024 Safari/537.36 MicroMessenger/6.5.4.1000 NetType/4G Language/zh_CN
2018-08-24 15:07:23	http://wanai.unetu.net/	Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1
2018-08-24 15:07:41	http://wanai.unetu.net/vip/relay_login?invited=&via=mobile	Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1
2018-08-24 15:08:09	http://wanai.unetu.net/branch/palipay_return/vip/0?body=3%E5%BC%A030%E5%85%83%E4%BB%A3%E9%87%91%E5%88%B8&is_success=T&notify_id=RqPnCoPT3K9%252Fvwbh3Ih134mxINMlIGTG%252B9kID%252FwiGx4c1FnkV%252BooSK3CMdbONBwJlaco&notify_time=2018-08-24+15%3A08%3A03&notify_type=trade_status_sync&out_trade_no=20180824-500001-150601_10094&payment_type=1&seller_id=2088911951177304&service=alipay.wap.create.direct.pay.by.user&subject=29%E5%85%83%E8%B4%AD%E4%B9%B0%E4%B8%87%E7%88%B1%E4%BB%A3%E9%87%91%E5%88%B8%E6%8E%A5%E9%BE%99&total_fee=0.02&trade_no=2018082422001463961001437388&trade_status=TRADE_SUCCESS&sign=QcnyPraS%2FMLpTcAqns0y%2FWvAZrMBML0zZHKI4%2FpLRYzhcBc0BGvRAXgTEZH1rEgWJOOKB3MuI54OjsXvHNdseme4c1Us4DXfMt4zNZoNhXohWHWbCz7lX2xgQfe2Kd6ex9VPhL3gVS4wR0pjhCedYAbeIkqsuH3sIQAxTh9bPjg%3D&sign_type=RSA	Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1
2018-08-24 15:10:18	/vip/relay_info?invited=DVMTUzNTA5NDQ4OWV5SnBaQ0k2SWpFMk9TSjk=&via=share	Mozilla/5.0 (iPhone; CPU iPhone OS 9_3 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13E230 ChannelId(3) Nebula PSDType(1) AlipayDefined(nt:WIFI,ws:320|504|2.0) AliApp(AP/9.9.0.000001) AlipayClient/9.9.0.000001 Language/zh-Hans ProductType/dev
2018-08-24 15:10:22	/vip/relay_start?invited=DVMTUzNTA5NDQ4OWV5SnBaQ0k2SWpFMk9TSjk=&via=none	Mozilla/5.0 (Linux; U; Android 8.0.0; zh-CN; ONEPLUS A3010 Build/OPR1.170623.032) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.108 UCBrowser/11.8.8.968 UWS/2.13.2.11 Mobile Safari/537.36 UCBS/2.13.2.11_180731180537 NebulaSDK/1.8.100112 Nebula AlipayDefined(nt:WIFI,ws:411|0|2.625,ac:sp) AliApp(AP/10.1.30.663) AlipayClient/10.1.30.663 Language/zh-Hans useStatusBar/true isConcaveScreen/false
2018-08-24 15:10:46	/vip/relay_info?invited=DVMTUzNTA5NDQ4OWV5SnBaQ0k2SWpFMk9TSjk=&via=share	Mozilla/5.0 (Linux; U; Android 8.0.0; zh-CN; ONEPLUS A3010 Build/OPR1.170623.032) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.108 UCBrowser/11.8.8.968 UWS/2.13.2.11 Mobile Safari/537.36 UCBS/2.13.2.11_180731180537 NebulaSDK/1.8.100112 Nebula AlipayDefined(nt:WIFI,ws:411|0|2.625,ac:sp) AliApp(AP/10.1.30.663) AlipayClient/10.1.30.663 Language/zh-Hans useStatusBar/true isConcaveScreen/false
2018-08-24 15:11:07	http://wanai.unetu.net/vip/relay_info?invited=DVMTUzNTA5NDQ4OWV5SnBaQ0k2SWpFMk9TSjk=&via=share	Mozilla/5.0 (Linux; U; Android 8.0.0; zh-CN; ONEPLUS A3010 Build/OPR1.170623.032) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.108 UCBrowser/11.8.8.968 UWS/2.13.2.11 Mobile Safari/537.36 UCBS/2.13.2.11_180731180537 NebulaSDK/1.8.100112 Nebula AlipayDefined(nt:WIFI,ws:411|0|2.625,ac:sp) AliApp(AP/10.1.30.663) AlipayClient/10.1.30.663 Language/zh-Hans useStatusBar/true isConcaveScreen/false

JavaScript 实现 Toast 吐司效果

JS

<script>
function Toast(msg,duration){
    duration=isNaN(duration)?3000:duration;
    var m = document.createElement('div');
    m.innerHTML = msg;
    m.style.cssText="width: 60%;min-width: 150px;opacity: 0.7;height: 30px;color: rgb(255, 255, 255);line-height: 30px;text-align: center;border-radius: 5px;position: fixed;top: 40%;left: 20%;z-index: 999999;background: rgb(0, 0, 0);font-size: 12px;";
    document.body.appendChild(m);
    setTimeout(function() {
        var d = 0.5;
        m.style.webkitTransition = '-webkit-transform ' + d + 's ease-in, opacity ' + d + 's ease-in';
        m.style.opacity = '0';
        setTimeout(function() { document.body.removeChild(m) }, d * 1000);
    }, duration);
}
</script>

HTML

<html>
	<head>
	<style>
	body {
		font-family: 'Lucida Grande', 'Helvetica', sans-serif;
	}
	</style>
	</head>
	<body>
	<button onclick="Toast('这是一个吐司',2000);">Toast</button>
	</body>
</html>

jQuery 短信获取倒计时

<head>
	<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
</head>

<input id="smspwd" type="button" value="短信获取" onclick='getSMS()'>

<script type="text/javascript">		
	function getSMS(){
		console.log(1)
		$("#smspwd").smsCountdown({begin: 10})
	}
</script>


<script type="text/javascript">		
	$.fn.extend({
		smsCountdown:function(){
			var params = {
				begin: arguments[0].begin || 0,
				way: arguments[0].way || 'input'
			};
			var $me = this;
			if(params.begin>0){
				$me.attr('disabled',true);
				var count = params.begin;		
				if(params.way == 'button'){
					var resend = setInterval(function(){
						count--;
						if (count > 0){
							$me.html("\u7b49\u5f85"+count+"\u79d2");
						}else {
							clearInterval(resend);
							$me.removeAttr("disabled").html("\u77ed\u4fe1\u83b7\u53d6");
						}
					}, 1000);
				}else{
					var resend = setInterval(function(){
						count--;
						if (count > 0){
							$me.val("\u7b49\u5f85"+count+"\u79d2");
						}else {
							clearInterval(resend);
							$me.removeAttr("disabled").val("\u77ed\u4fe1\u83b7\u53d6");
						}
					}, 1000);
				}
			}else{
				if(params.way == 'button'){
					$me.removeAttr("disabled").html("\u77ed\u4fe1\u83b7\u53d6");
				}else{
					$me.removeAttr("disabled").val("\u77ed\u4fe1\u83b7\u53d6");
				}
			}
		},
	})
</script>