I’m trying to send some XML data using CURL in a foreach loop.
Data is getting passed sometimes with a success response also TIMEDOUT error sometimes.
foreach($contents as $key=>$val){
$dataCD='';
$dataCD.="<arg0>
*some data*
</arg0>";
$data="<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://example.com/">
<soapenv:Header/>
<soapenv:Body>";
$data.=$dataCD;
$data.="</soapenv:Body>
</soapenv:Envelope>";
$curl = curl_init();
curl_setopt_array($curl, array(
//live
CURLOPT_URL => "https://example.com",
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $data,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_HTTPHEADER => array("Content-Type: text/xml","User-Agent: Mozilla/5.0"),
CURLOPT_TIMEOUT => 60, // Increase the timeout to 60 seconds
CURLOPT_CONNECTTIMEOUT => 30, // Timeout to establish connection
CURLOPT_VERBOSE => true, // Enable verbose output
CURLOPT_FAILONERROR => true,
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
// $text= $data;
if($err)
{
$logs = '[ '.date('Y-m-d H:i:s',time()).'] [ error ] '.$err."rn";
$logfile = fopen('E:xampphtdocsprojecterrors_test.log','a','1');
fwrite($logfile, $logs);
fclose($logfile);
}
}
I’m getting below error for few data
[ 2024-09-05 11:09:31] [ error ] Failed to connect to example.com
port 443: Timed out
I’ve included below option to increase timeout too.
CURLOPT_TIMEOUT => 60, CURLOPT_CONNECTTIMEOUT => 30,
Looking for some suggestions, thanks in advance.
2