当curl或file_get_contents请求https url时,php-fpm崩溃 [英] php-fpm crashed when curl or file_get_contents request a https url

查看:228
本文介绍了当curl或file_get_contents请求https url时,php-fpm崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务器是nginx + php-fpm

My server is nginx + php-fpm

代码将导致错误

file_get_contents('https://github.com');

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://github.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch); //crash here
curl_close($ch);

网页显示502错误

nginx日志是


[error] 2656#0:* 541 recv()失败上游

[error] 2656#0: *541 recv() failed (104: Connection reset by peer) while reading response header from upstream

fpm日志是


03:00:37:37.619903 [通知] fpm_got_signal(),第48行:收到SIGCHLD

Jul 03 00:37:37.619903 [NOTICE] fpm_got_signal(), line 48: received SIGCHLD

7月03 00:37:37.619926 [警告] fpm_children_bury孩子3567(池默认)退出信号11 SIGSEGV(核心转储)从开始417.576755秒后

Jul 03 00:37:37.619926 [WARNING] fpm_children_bury(), line 215: child 3567 (pool default) exited on signal 11 SIGSEGV (core dumped) after 417.576755 seconds from start

7月03 00:37:37.620807 [注意] fpm_children_make 352:child 4193(pool default)started

Jul 03 00:37:37.620807 [NOTICE] fpm_children_make(), line 352: child 4193 (pool default) started

如果请求网址以http://开头,一切正常。

If the request url starts with http:// , everything is OK .

php configure命令是

php configure command is

'./configure' '--prefix=/www/nginx_php-5.2.17' '--with-config-file-path=/www/nginx_php-5.2.17/etc' '--with-mysql=/www/mysql' '--with-iconv=/usr' '--with-freetype-dir' '--with-jpeg-dir' '--with-png-dir' '--with-zlib' '--with-libxml-dir=/usr' '--enable-xml' '--disable-rpath' '--enable-discard-path' '--enable-inline-optimization' '--with-curl' '--enable-mbregex' '--enable-mbstring' '--with-mcrypt=/usr' '--with-gd' '--enable-gd-native-ttf' '--with-openssl' '--with-mhash' '--enable-ftp' '--enable-sockets' '--enable-zip' '--enable-fastcgi' '--enable-fpm' '--with-fpm-conf=/www/etc/php-fpm.conf'


推荐答案

尝试添加以下两项:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

他们会阻止SSL证书的验证。问题,因为验证可能失败。除非必须验证来源,在使用 cURL 下载数据时,始终添加这两行。

They will prevent the verification of the SSL certificate. This might be the issue as the verification might fail. Unless it's mandatory to verify the source, always add these 2 lines when downloading data with cURL.

PS

这篇关于当curl或file_get_contents请求https url时,php-fpm崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆