首页 文章

当curl或file_get_contents请求https url时,php-fpm崩溃了

提问于
浏览
3

我的服务器是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日志是

[错误] 2656#0:* 541 recv()失败(104:通过对等方重置连接)从上游读取响应头

fpm日志是

Jul 03 00:37:37.619903 [NOTICE] fpm_got_signal(),第48行:收到SIGCHLD Jul 03 00:37:37.619926 [警告] fpm_children_bury(),第215行:孩子3567(池默认值)退出信号11 SIGSEGV(核心从7月03日00:37:37.620807开始417.576755秒之后[通知] fpm_children_make(),第352行:子4193(池默认值)已启动

如果请求URL以http://开头,则一切正常 .

php configure命令是

'./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'

1 回答

  • 1

    尝试添加这两个:

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

    They will prevent the verification of the SSL certificate. 这可能是问题,因为验证可能会失败 . 除非必须验证源,否则在使用 cURL 下载数据时,请始终添加这两行 .

    PS :不确定这会对你有所帮助 .

相关问题