解决执行 pecl upgrade-all 提示 Error getting channel info from pear.php.net: Connection to `ssl://pear.php.net:443' failed:Connection to 'ssl://pecl.php.net:443' failed: Unable to find the socket 错误。

出现这个错误主要是因为缺失默认证书导致的,具体原因不明。

下面说一下解决方案:

1、查看 default_cert_file 的路径

php -r "print_r(openssl_get_cert_locations());"

2、下载证书

wget -P /etc/ssl/ http://curl.haxx.se/ca/cacert.pem
chmod 744 /etc/ssl/cacert.pem

注意:其中 /etc/ssl/cacert.pem 替换为自己的真实路径

我们以Nginx 1.18.0为例子,手动编译升级Nginx,使Nginx支持HTTP2和TLS 1.3。

一、准备编译环境

1、检查 OpenSSL 版本

由于 TLS 1.3 需要 OpenSSL 1.1.1 或更高的版本支持,所以为了确保TLS1.3的正常运行,先检查 OpenSSL 版本

openssl version

OpenSSL 1.0.2k-fips 26 Jan 2017

如果低于 OpenSSL 1.1.1,请参考 https://www.24kplus.com/linux/97.html 升级 OpenSSL

2、安装依赖库

yum -y install libxml2 libxml2-devel libxslt-devel gd-devel gperftools libuuid-devel libblkid-devel libudev-devel fuse-devel libedit-devel libatomic_ops-devel gcc-c++

如果要启用 GeoIP2 模块,还需要安装 libmaxminddb;启用 IP2Location 模块需要安装 IP2Location C Library

3、获取上一次编译的参数

nginx -V

把红色框框的参数拷贝出来,后面会用到。

二、下载&编译&升级

1、下载解压

wget https://nginx.org/download/nginx-1.18.0.tar.gz
tar -xvf nginx-1.18.0.tar.gz
cd nginx-1.18.0

2、配置编译参数

把原版本编译参数(上面拷贝出来的)粘贴上去,如果 --with-http_v2_module 参数没有则在最后加入一行 --with-http_v2_module

./configure \
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib64/nginx/modules
......
--with-http_v2_module

3、编译

make

4、升级 Nginx

停止 Nginx 服务

systemctl stop nginx

备份旧版本 Nginx

注意:sbin实际路径可能和教程的不一样,具体路径看 nginx -V 命令输出的 --sbin-path 参数

cp /usr/sbin/nginx /usr/sbin/nginx.bak

拷贝新版本到 /usr/sbin

cp objs/nginx /usr/sbin/

开始升级 Nginx

make upgrade

最后,启动 Nginx

systemctl start nginx

5、检查升级结果

nginx -V

C# .NET Hallo world

要解决中文乱码问题,首先我们需要知道原因,一开始我尝试了gb2312,utf-8等多种编码格式导出,使用 Execl 打开均为乱码,后来无意中发现,必须为“带 BOM 的 UTF-8”。

代码示例:

using(var sw = new File.CreateText(fileName))
{
	sw .WriteLine(csvContent);
}

如果是asp.net页面输出,则为:

Response.Clear();
Response.Buffer = true;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToShortDateString() + fileName + ".xls");
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.Charset = "utf-8";
Response.ContentType = "text/csv";
using(var outputWriter = new StreamWriter(Response.OutputStream, System.Text.Encoding.UTF8))
{
	outputWriter.WriteLine(csvContent);
}
Response.Flush();
Response.End();