php curl常见错误:SSL错误、bool(false)


Posted in PHP onDecember 28, 2011

症状:php curl调用https出错
排查方法:在命令行中使用curl调用试试。
原因:服务器所在机房无法验证SSL证书。
解决办法:跳过SSL证书检查。
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

症状:php curl调用curl_exec返回bool(false),命令行curl调用正常。
排查方法:
var_dump(curl_error($ch));
返回:
string(23) "Empty reply from server"
再排查:
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
返回:
HTTP/1.1 100 Continue
Connection: close
原因:php curl接收到HTTP 100就结束了,应该继续接收HTTP 200
解决方案:
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));

PHP and cURL: Disabling 100-continue header
Published June 15th, 2006
I've been using cURL (through PHP) to build a sort of proxy for a project I'm working on. I need to parse the returned headers (to recover the HTTP status), so had included a very simple script to do so. It had worked fine in the past, but for some reason barfed in this case. A closer look at what was being returned revealed that for some reason, Apache was prepending the ‘normal' headers with an extra response header:

HTTP/1.1 100 Continue

HTTP/1.1 200 OK Date: Fri, 09 Jun 2006 15:23:42 GMT
Server: Apache
...A bit of Googling revealed that this was to do with a header that cURL sends by default:

Expect: 100-continue

…which in turns tells Apache to send the extra header. I poked around a fair bit but couldn't quite find a workable solution short of manually removing the header in PHP, which seemed a bit clumsy. Finally, on a hunch I tried this:

curl_setopt( $curl_handle, CURLOPT_HTTPHEADER, array( 'Expect:' ) );

…which basically overrides the original ‘Expect:' header with an empty one.

Hope this helps someone.

PHP 相关文章推荐
计算2000年01月01日起到指定日的天数
Oct 09 PHP
手把手教你使用DedeCms V3的在线采集图文教程
Apr 03 PHP
提高PHP编程效率 引入缓存机制提升性能
Feb 15 PHP
linux下编译安装memcached服务
Aug 03 PHP
PHP中防止SQL注入方法详解
Dec 25 PHP
php定义参数数量可变的函数用法实例
Mar 16 PHP
Ubuntu中启用php的mail()函数并解决发送邮件速度慢问题
Mar 27 PHP
php验证身份证号码正确性的函数
Jul 20 PHP
PHP计算近1年的所有月份
Mar 13 PHP
PHP中include和require的区别实例分析
May 07 PHP
php批量删除操作(数据访问)
May 23 PHP
laravel高级的Join语法详解以及使用Join多个条件
Oct 16 PHP
PHP+Ajax异步通讯实现用户名邮箱验证是否已注册( 2种方法实现)
Dec 28 #PHP
shopex主机报错误请求解决方案(No such file or directory)
Dec 27 #PHP
PHP写UltraEdit插件脚本实现方法
Dec 26 #PHP
url decode problem 解决方法
Dec 26 #PHP
最新用php获取谷歌PR值算法,附上php查询PR值代码示例
Dec 25 #PHP
匹配csdn用户数据库与官方用户的重合度并将重叠部分的用户筛选出来
Dec 25 #PHP
php操作JSON格式数据的实现代码
Dec 24 #PHP
You might like
php防攻击代码升级版
2010/12/29 PHP
如何把php5.3版本升级到php5.4或者php5.5
2015/07/31 PHP
php判断用户是否关注微信公众号
2016/07/22 PHP
thinkPHP5 ACL用户权限模块用法详解
2017/05/10 PHP
php图片裁剪函数
2018/10/31 PHP
jQuery 连续列表实现代码
2009/12/21 Javascript
基于jQuery的表格操作插件
2010/04/22 Javascript
js数值和和字符串进行转换时可以对不同进制进行操作
2014/03/05 Javascript
javascript+html5实现仿flash滚动播放图片的方法
2015/04/27 Javascript
jQuery中 prop() attr()使用详解
2015/05/19 Javascript
详解vue-cli构建项目反向代理配置
2017/09/07 Javascript
javaScript中的空值和假值
2017/12/18 Javascript
Vuex中mutations与actions的区别详解
2018/03/01 Javascript
Vue.js构建你的第一个包并在NPM上发布的方法步骤
2019/05/01 Javascript
ant-design-vue 快速避坑指南(推荐)
2020/01/21 Javascript
Python多线程中阻塞(join)与锁(Lock)使用误区解析
2018/04/27 Python
Python切片操作深入详解
2018/07/27 Python
简单了解python的break、continue、pass
2019/07/08 Python
Python 数据的累加与统计的示例代码
2020/08/03 Python
pytorch 实现L2和L1正则化regularization的操作
2021/03/03 Python
HTML5 transform三维立方体实现360无死角三维旋转效果
2014/08/22 HTML / CSS
全球采购的街头服饰和帽子:Urban Excess
2020/10/28 全球购物
西部世纪面试题
2014/12/05 面试题
介绍下Lucene建立索引的过程
2016/03/02 面试题
主题教育活动总结
2014/05/05 职场文书
假面舞会策划方案
2014/05/29 职场文书
县级领导干部开展党的群众路线教育实践活动工作汇报
2014/10/25 职场文书
学校师德师风整改方案
2014/10/28 职场文书
工厂清洁工岗位职责
2015/02/14 职场文书
施工安全保证书
2015/05/09 职场文书
2016优秀教师先进个人事迹材料
2016/02/25 职场文书
演讲稿之我的初心我的成长
2019/08/12 职场文书
《狼王梦》读后感:可怜天下父母心
2019/11/01 职场文书
读《方与圆》有感:交友方圆有度
2020/01/14 职场文书
php 获取音视频时长,PHP 利用getid3 获取音频文件时长等数据
2021/04/01 PHP
如何使用php生成zip压缩包
2021/04/21 PHP