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

标签 curl nginx openssl php

我的服务器是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() failed (104: Connection reset by peer) while reading response header from upstream

fpm日志是

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

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

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

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

php配置命令是

'./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 下载数据时始终添加这两行。

附言:不确定这是否对您有帮助。

关于curl - 当 curl 或 file_get_contents 请求 https url 时,php-fpm 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17439199/

相关文章:

nginx - 如何从 dockerised nginx 到达另一个容器

python 请求 SSL 错误(证书验证失败)

c - 我如何通过 easy-ecc 将来自 OpenSSL 的 key 用于 ECDSA (prime256v1)?

python - fatal error C1083 : Cannot open include file: 'openssl/opensslv.h'

php - 如何在 cURL php 中发布 JSON 数据和请求 token (在 header 中)

javascript - Node.js POST 不起作用

nginx - 如何使用 nginx 进行 kerberos 身份验证

ruby - Mailgun::CommunicationError 通过 nginx '301 Moved Permanently' 错误

ruby - 如何使用 'wget'安装RVM?

php - php 中的 cron 作业命中 100 多个动态 url 以缓存页面