I have a reasonably simple PHP that runs several curls based on PHP POST values from a form. Once it mangles the POST'd variables as I need it to, it runs 4 curl_init/curl_exec/curl_close in series.
It runs the first 2 curls fine, and prints my output/debug as required. It reaches a third curl, which seems to execute and POST perfectly fine, but doesn't seem to do anything after that. I have basic error capturing (parse JSON response for array/value, if array, echo error, else echo no error).
When no error is encountered with the problem curl, it seems to not continue. However, if there is an error, it continues. Note I am not explicitly telling the code to continue, it's just a very basic "if else" in PHP. This is for debug, and when I find out why it's misbehaving, die will be used to exit. I do not tell it to break or die.
This third, "blocking" curl is the same endpoint as the previous two and returns the same valid JSON as the first two curl calls. I want to know why the script seems to stop when no error is encountered. Is it not continuing due to an open connection? I tried adding "connection close" headers to the problem curl but no difference, as well as a timeout via CURLOPTS.
Below is the code structure used for each cURL.
$curl = curl_init();
echo "<p>Opening curl for <theApplication></p>";
curl_setopt_array($curl, array(
CURLOPT_URL => '<theEndpoint>',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 1,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'<validJSON>',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
$data = json_decode($response);
$results = $data->result[0];
$maintenanceid = $results->ids[0];
$errors = $data->error->data;
if ($errors) {
echo "<p><font color='red'>Error: ".$errors."</font></p>";
} else {
echo "<p><font color='green'>No errors!</font></p>";
};
curl_close($curl);
echo "<p>Finished the curl! Why aren't you printing me!</p>";