displaying a message while CURL waits?
Posted: Wed Feb 03, 2010 5:23 am
Hi all,
Can anyone help with a small CURL issue? I am calling a URL with CURL which may take up to 60 seconds to respond. It's usually a lot quicker but in any event I want to show the user a message or a spinning wheel graphic while CURL is doing it's thing. At the moment I've mocked up the remote API using the usleep function to hold for 10 seconds, but all I can see is a blank page until the 10 seconds is up.
Here is my current script:
Basically I'm not seeing the first printed message "activating... please wait" until CURL has finished.
Can anyone help?
Many thanks
Kevin
Can anyone help with a small CURL issue? I am calling a URL with CURL which may take up to 60 seconds to respond. It's usually a lot quicker but in any event I want to show the user a message or a spinning wheel graphic while CURL is doing it's thing. At the moment I've mocked up the remote API using the usleep function to hold for 10 seconds, but all I can see is a blank page until the 10 seconds is up.
Here is my current script:
Code: Select all
<?php
print("activating... please wait<br/>");
$API_Endpoint = "http://mydevsiteurl/remoteActivation.php";
$nivioRef = 111;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
// Turn off the server and peer verification (TrustManager Concept).
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$nvpreq = "REF=$nivioRef";
// Set the request as a POST FIELD for curl.
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
// Get response from the server.
$httpResponse = curl_exec($ch);
if(!$httpResponse) {
exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')');
}
// Extract the response details.
$httpResponseAr = explode("&", $httpResponse);
print_r($httpResponseAr);
?>Can anyone help?
Many thanks
Kevin