标签 PHP 下的文章

//?? 等价于 isset
$a = '';
$b = isset($a) ? $a : 'hahha';
$b = $a ?? 'hahha';
//$b is ''
//适用于多层级array的属性读取
$arr = [ 'son'=>['name'=>'child'] ];
echo $arr['son']['age'] ?? '19';
//output: 19
echo $arr['non']['name'] ?? 'non child';
//output: non child

//?: 等价于empty
$c = empty($a) ? 'hahaha' : $a;
$c = $a ?: 'hahaha';
//c is 'hahaha'

 

在PHP中使用curl进行HTTP请求,`$usePost`设置为true可以使用post请求。

<!--?php
header("Content-type: text/html; charset=utf-8"); //设置返回内容编码
/**
 * 模拟HTTP请求
 * @param string $url
 * @param array $post_data
 */
function request($url = '',$post_data = array(),$usePost=false) {
    if (empty($url) || empty($post_data)) {
        return false;
    }
    $ch = curl_init();//初始化curl
    curl_setopt($ch, CURLOPT_URL,$url);//设置网址
    curl_setopt($ch, CURLOPT_HEADER, 0);//不要返回的Header区域内容
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串
    curl_setopt($ch, CURLOPT_POST, $usePost);//是否以post方式提交数据
    curl_setopt($ch, CURLOPT_ENCODING, "");//设置自动解压压缩的返回内容
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);//设置提交的数据
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不验证证书下同
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //不验证证书下同
    $data = curl_exec($ch);//运行curl
    curl_close($ch);
    return $data;
}

$url = 'https://some.domain/somepath';
$post_data = array('param1'=>'value1','param2'=>'value2');
$res = request($url, $post_data); 
echo $res;

 

一、Nginx安装

yum install nginx -y

二、PHP-FPM安装

yum install epel-release -y 
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

安装php7.1 

yum install php71w-fpm php71w-gd php71w-common php71w-mysql 

安装php7.2

yum install php72w-fpm php72w-gd php72w-common php72w-mysqlnd 

三、安装MariaDB

vim /etc/yum.repos.d/maradb.repo

输入以下内容保存

# MariaDB 10.3 CentOS repository list - created 2019-05-11 08:24 UTC 
# http://downloads.mariadb.org/mariadb/repositories/ 
[mariadb] 
name = MariaDB 
baseurl = http://yum.mariadb.org/10.3/centos7-amd64 
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB 
gpgcheck=1
yum install -y MariaDB-server MariaDB-client