I got this weird error, CURL ERROR: Error Recv: connection reset using peer
This is how it happens, if I did not connect to the server and suddenly try to connect to the server via CURL in PHP, I get an error. When I run the CURL script again, the error disappears and then works well all the time if I leave on the remote server for about 30 minutes or reboot the remote server and try to connect again, I will get the error again. So it looks like the connection is idle and then suddenly the server wakes up and then works and then sleeps again.
This is what my CURL script looks like.
$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);
I have a lot of ideas and solutions, please help, I will be grateful!
If I complete the output to see what happens with
curl_setopt ($c, CURLOPT_VERBOSE, TRUE); curl_setopt($c, CURLOPT_STDERR, $fp);
I get the following
* About to connect() to 196.41.139.168 port 80 (#0) * Trying 196.xxx.. * connected * Connected to 196.xxx (196.xxx) port 80 (#0) > POST /serve/?r=pdf/generatePdf HTTP/1.1 Host: 196.xxx 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
I added the following header to remove the default header and still no luck:
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