php curl rst,CURL错误:接收失败:对等重置连接-PHP Curl

我遇到这个奇怪的错误, CURL错误:接收失败:对等连接重置

如果我没有连接到服务器,而突然尝试通过PHP中的CURL连接到服务器,则会出现此错误。当我再次运行CURL脚本时,错误消失,然后在整个过程中都正常运行,如果我将远程服务器保持空闲状态约30分钟或重新启动远程服务器并尝试重新连接,则我会再次收到该错误。因此,似乎连接处于空闲状态,然后突然服务器唤醒,然后工作,然后再次进入睡眠状态。

这就是我的CURL脚本的外观。

$url = Yii::app()->params['pdfUrl'];

$body = 'title='.urlencode($title).'&client_url='.Yii::app()->params['pdfClientURL'].'&client_id='.Yii::app()->params['pdfClientID'].'&content='.urlencode(htmlentities($content));

$c = curl_init ($url);

$body = array(

"client_url"=>Yii::app()->params['pdfClientURL'],

"client_id"=>Yii::app()->params['pdfClientID'],

"title"=>urlencode($title),

"content"=>urlencode($content)

);

foreach($body as $key=>$value) { $body_str .= $key.'='.$value.'&'; }

rtrim($body_str,'&');

curl_setopt ($c, CURLOPT_POST, true);

curl_setopt ($c, CURLOPT_POSTFIELDS, $body_str);

curl_setopt ($c, CURLOPT_RETURNTRANSFER, true);

curl_setopt ($c, CURLOPT_CONNECTTIMEOUT , 0);

curl_setopt ($c, CURLOPT_TIMEOUT , 20);

$pdf = curl_exec ($c);

$errorCode = curl_getinfo($c, CURLINFO_HTTP_CODE);

$curlInfo = curl_getinfo($c);

$curlError = curl_error($c);

curl_close ($c);

我完全没有想法和解决方案,请帮忙,我将不胜感激!!!

如果我详细输出以查看使用会发生什么

curl_setopt ($c, CURLOPT_VERBOSE, TRUE);

curl_setopt($c, CURLOPT_STDERR, $fp);

我得到以下

* About to connect() to 196.41.139.168 port 80 (#0)

* Trying 196.x.x.x... * connected

* Connected to 196.x.x.x (196.x.x.x) port 80 (#0)

> POST /serve/?r=pdf/generatePdf HTTP/1.1

Host: 196.x.x.x

Accept: */*

Content-Length: 7115

Content-Type: application/x-www-form-urlencoded

Expect: 100-continue

* Recv failure: Connection reset by peer

* Closing connection #0

012 20:23:49 GMT

< Server: Apache/2.2.15 (CentOS)

< X-Powered-By: PHP/5.3.3

< Connection: close

< Transfer-Encoding: chunked

< Content-Type: text/html; charset=UTF-8

<

* Closing connection #0

我在下面的脚趾中添加了默认标题,但仍然没有运气:

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

> Accept: */* Content-Length: 8414 Content-Type:

> application/x-www-form-urlencoded

>

> * Recv failure: Connection reset by peer

> * Closing connection #0 r: Apache/2.2.15 (CentOS) < X-Powered-By: PHP/5.3.3 < Connection: close < Transfer-Encoding: chunked <

> Content-Type: text/html; charset=UTF-8 <

> * Closing connection #0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值