作者归档:myjoyoo
CentOS下,curl和wget返回都很慢,但ping确很快的原因
公司内网有几台CentOS服务器,发现网络很慢,但ping和telnet ip port都很快。
在wget的时候,解析主机花了很多时间,花了很久的时间排查下来是因为ipv4和ipv6有冲突,需要在
/etc/resolv.conf
后面加上
options single-request-reopen
就解决了,参考:
https://serverfault.com/questions/858649/slow-responses-with-curl-and-wget-on-centos-7
tmux使用手记
会话管理
tmux new -s 会话名字:建立一个新的会话
tmux attach -t 序号或会话名字: 连接到会话
^b+s: 列出所有会话进行切换
^b+d: 退出会话并在后台运行
窗口管理
^b+c: 建立新窗口
^b+w: 列出所有窗口进行切换
^b+&: 退出窗口
^b+n: 切换到下一个窗口
^b+p: 切换到上一个窗口
面板管理
^b+双引号: 垂直分隔
^b+%: 水平分隔
^b+箭头: 在不同的面板之间切换
^b+o: 在不同面板之间循环切换
^b+x: 关闭pane,和关闭窗口一样
^b+q: 显示各面板的编号
编辑操作
^b+[: 进入复制模式,相当于vi的命令格式,可以用vi命令进行移动光标
其它技巧
命令行删除从光标到头的命令: ^u, 从光标删除到末: ^k
让FPM以root用户运行
fpm默认是不能以root用户运行的,会报:
ERROR: [pool www] please specify user and group other than root
如果有特殊原因,需要以root用户运行,需要修改配置,以让fpm支持以root用户的方式运行fpm
vim /lib/systemd/system/php-fpm.service
把:
ExecStart=/usr/sbin/php-fpm –nodaemonize
修改成:
ExecStart=/usr/sbin/php-fpm -R –nodaemonize
改完后,需要执行:
systemctl daemon-reload
以生效修改
再执行,重启fpm进程
systemctl restart php-fpm
如果之前的fpm是手动运行的,需要以发送Linux信号的方式停止fpm服务,如果开启的fpm进程较多,要多等一会儿,等子进程完了再systemctl start php-fpm,不然会出现端口被占用,无法启动的情况
kill -SIGKILL [fpm master的进程号]
正则手记
这几个老是容易忘记
- 在多个字符串中选择一个字符串匹配
111(?:abc|def)222
- 只匹配hello php和java中的hello, 不匹配hello python中的hello
hello (?=php|java)
- 只匹配除 hello python和javascript外的其它串中的hello
hello (?!python|javascript)
- 只匹配dan或john is a good man中的is a good man
(?<=dan|john) is a good man
- 只匹配除dan和john以外中的is a good man
(?<!dan|john) is a good man
CURL报”426 Unsupported SSL protocol TLSv1.2″时,升级curl, openssl, php-curl
服务器上php 5.6调用curl时,返回”426 Unsupported SSL protocol TLSv1.2, Upgrade to TLSv1.3 is required”.
用”openssl ciphers -V | column -t“ 查看,原来是openssl不支持TLSv1.3,需要升级,但由于PHP的CURL扩展是调用的Curl,Curl再调用的openssl,所以需要把openssl和curl升级,把php-curl重新编译.
思路是重新安装openssl和curl到新目录,以防止破坏以前的依赖,不然就容易翻车。
一、升级openssl
去https://www.openssl.org/source/下载v1版本,因为我是php5,系统也比较老,下载v1保险一些。
./config –prefix=/usr/local/openssl
make
make install
完成后测试下: /usr/local/openssl/bin/openssl version,
可能会报错:
bin/openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory
建立软链
ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/lib64/libssl.so.1.1
ln -s /usr/local/openssl/lib/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
二、升级CURL
去官网下载最新的curl,按标准安装方法,把curl安装到/usr/local/curl目录,需要指定上面新的openssl目录
./configure –prefix=/usr/local/curl –with-ssl=/usr/local/openssl
完成后可以测试一下,是否可以下载TLSv1.3的URL内容,如果没有问题就到三步
三、重新编译php-curl
去PHP官网下载和你当前版本一样的原码,解压,注意要指定新的curl目录
/root/software/php-5.6.40/ext/curl
phpize
./configure –with-curl=/usr/local/curl/
make
make install
如果是php8的curl扩展到这一步要报错:
checking for cURL support… yes, shared
checking for libcurl >= 7.29.0… no
configure: error: Package requirements (libcurl >= 7.29.0) were not met:
No package ‘libcurl’ found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables CURL_CFLAGS
and CURL_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
要这样才可以
export PKG_CONFIG_PATH=/usr/local/curl/lib/pkgconfig
报下面的错误的话要这样:
libtool: compile: cc -I. -I/root/software/php-8.3.1/ext/curl -I/root/software/php-8.3.1/ext/curl/include -I/root/software/php-8.3.1/ext/curl/main -I/root/software/php-8.3.1/ext/curl-I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/local/curl/include/ -DHAVE_CONFIG_H -g -O2 -D_GNU_SOURCE -DZEND_COMPILE_DL_EXT=1 -c /root/software/php-8.3.1/ext/curl/interface.c -MMD -MF interface.dep -MT interface.lo -fPIC -DPIC -o .libs/interface.o
/root/software/php-8.3.1/ext/curl/interface.c:58:28: fatal error: zend_smart_str.h: No such file or directory
./configure –with-curl=/usr/local/curl –with-php-config=/opt/remi/php83/root/bin/php-config
报下面的错误的话要这样make:
/root/software/php-8.3.1/ext/curl/multi.c: In function ‘curl_multi_get_gc’:
/root/software/php-8.3.1/ext/curl/multi.c:572:2: error: ‘for’ loop initial declarations are only allowed in C99 mode
或者修改代码,把那一行的行内定义提出去,或者用下面的命令编译:
make CFLAGS=-std=c99
最后测试一下:
php -r “phpinfo();” | grep cURL
输出
cURL support => enabled
cURL Information => 8.2.1
没有问题,如果是fpm,要重启fpm。
其它的问题
如果在编译的时候出现很多语法错误,有可能是系统安装了多个php版本,引用到了错误的php头文件,在.configure的时候,要指定–with-php-config
安装好扩展之后,但加载扩展如果出现下面的错误,是因为php扩展和curl的版本不对,需要下载新的curl版本重新安装。
PHP Warning: PHP Startup: Unable to load dynamic library ‘curl’ (tried: /opt/remi/php83/root/usr/lib64/php/modules/curl (/opt/remi/php83/root/usr/lib64/php/modules/curl: cannot openshared object file: No such file or directory), /opt/remi/php83/root/usr/lib64/php/modules/curl.so (/opt/remi/php83/root/usr/lib64/php/modules/curl.so: undefined symbol: curl_easy_escape)) in Unknown on line 0
nginx+php-fpm出现504的问题处理
nginx犯错误日志报:
2023/09/04 19:57:24 [error] 42010#42010: *1327 upstream timed out (110: Connection timed out) while reading response header from upstream, client: xxxx, server: localhost, request: “GET /xxxx HTTP/1.1”, upstream: “fastcgi://127.0.0.1:9082”, host: “xxx.xxx.xxx.xxx:3000”, referrer: “http://xxxx”
页面报504
检查以下部分:
1. php.ini的: max_execution_time设置
2. 检查fpm配置文件的 request_terminate_timeout 设置
3. 检查nginx的配置:
fastcgi_connect_timeout 3000s;
fastcgi_read_timeout 3000s;
怎么控制浏览器的Referer?
一、怎么禁止浏览器发送Referer头?
1、在HTML的<head>标签中添加以下meta标签:<meta name=”referrer” content=”no-referrer”>
2、用HTTP头中的”Referer-Policy”字段,可以在HTTP响应头中设置这个字段来控制浏览器如何发送referrer信息。例如:Referrer-Policy: no-referrer
2、怎么控制Referer的值
不能随意指定Referer值,但可以通过下面的代码把域名值作为Referer发送,而不是完全的URL: <meta content=”origin” name=”referrer”>
三、在HTML的Meta中,控制Referer的Meta主要有以下几种
1、<meta content=”no-referrer” name=”referrer”>:不发送Referer信息,但是不包括本站内的链接。
2、<meta content=”no-referrer-when-downgrade” name=”referrer”>:默认选项,https页面发https的referer,http页面发http的referer,不向不安全的地址发送referer。
3、<meta content=”origin” name=”referrer”>:只发送当前文档的来源(即Origin Header)。
4、<meta content=”origin-when-cross-origin” name=”referrer”>:当前文档和目标URL的域名相同,发送当前文档的完整URL,否则只发送当前文档的来源。
5、<meta content=”unsafe-url” name=”referrer”>:发送完整的URL,包括https到http的跨域跳转。
Laravel + Octane + Swoole配置
安装好Laravel和Swoole
composer require laravel/octane
php artisan octane:install
php artisan octane:start
这好像就可以了。。。
An auto json/url/timestamp encode/decode online tools.
In the development process, we often need to solve the timestamp, encode / decode the URL, and parse the JSON. It is inconvenient to open several pages,
So in my spare time, I made an online tool that can automatically encode and decode JSON, timestamp and URL.
You can try it.