月度归档:2023年09月

正则手记

这几个老是容易忘记

  • 在多个字符串中选择一个字符串匹配
    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;