displaying a message while CURL waits?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
the_lar
Forum Newbie
Posts: 4
Joined: Mon Aug 21, 2006 9:55 am

displaying a message while CURL waits?

Post by the_lar »

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:

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);
?>
Basically I'm not seeing the first printed message "activating... please wait" until CURL has finished.

Can anyone help?

Many thanks
Kevin
amargharat
Forum Commoner
Posts: 82
Joined: Wed Sep 16, 2009 2:43 am
Location: Mumbai, India
Contact:

Re: displaying a message while CURL waits?

Post by amargharat »

use ajax
the_lar
Forum Newbie
Posts: 4
Joined: Mon Aug 21, 2006 9:55 am

Re: displaying a message while CURL waits?

Post by the_lar »

Hi there, thanks for the tip but it's not really an option to use Ajax, as this is part of a payment process I have to be certain that everyone sees the message, not just those with Javascript
Post Reply