Hi there,
I'm writing an application that pulls from two separate web based APIs, collates the data into a single array of data. Once done, it then enters a loop that cycles through the array and executes a cURL call for each cycle. This worked perfectly for a controlled set of 10 artificial records and so I've started testing with live data.
On running the code, I eventually the following :
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
I'm not sure how to debug this and so I'm hoping I can find some help here.
I'm running WAMP, and the php.ini contains the following:
max_execution_time = 0 ; Maximum execution time of each script, in seconds
max_input_time = 0 ; Maximum amount of time each script may spend parsing request data
Through testing, I have discovered the following :
The script can do exactly 35 iterations through the loop in under 2 minutes.
Any number greater than this causes the error.
If I skip the first 20 curl submits, I can then do 21 to 55 iterations before failure, so I do not believe it is the 36th value.
If I put a sleep(5) command into the loop, I can still do 35 and no more iterations than that.
If I put a sleep(10) command into the loop, it fails on 35 and needs less.
$action = "post";
$url = "http://url.url.url/api/v1.0/udo_Position/create"; // I've replaced the actual URL out of necessity
// set user agent {
print("Setting CURL options, using URL ".$url."<br>");
$cd = curl_init();
curl_setopt($cd, CURLOPT_HEADER, 1);
curl_setopt($cd, CURLOPT_URL, $url);
curl_setopt($cd, CURLOPT_USERPWD, 'username:password');
curl_setopt($cd, CURLOPT_RETURNTRANSFER, 1); // Don't send return value to screen
curl_setopt($cd, CURLOPT_USERAGENT, "Firefox/2.0.0.1"); // spoofing FireFox 2.0
curl_setopt($cd, CURLOPT_VERBOSE, true);
// }
if ($action == 'get') {
;
} elseif ($action == 'post') {
print("POST set;<br>");
print("<pre style='font-family:verdana;font-size:13'>");
print_r($pointval);
print("</pre>");
$pointval["save"] = "Save"; // The AddNew step form requires this.
curl_setopt($cd, CURLOPT_POSTFIELDS, $pointval);
} else {
print("Invalid usage. Please see example<br>");
return;
}
$reply = curl_exec($cd);
$http_status = curl_getinfo($cd, CURLINFO_HTTP_CODE);
print("<pre style='font-family:verdana;font-size:13'>");
print_r($http_status);
print("</pre>");
print("Here is the reply from the AddNew function: <br>");
print("<pre style='font-family:verdana;font-size:13'>");
print_r($reply);
print("</pre>");
if (curl_error($cd)) {
print("Error: ".(curl_error($cd))."<br>");
}
curl_close($cd);
print("Insert Successful.<br>");
I am uncertain whether it is a PHP, Apache or cURL issue at this point. I have another script that pushes a great deal more cURL calls to the same system but pulls from only one external resource, instead of two. Any help or suggestions would be appreciated.