Monday, July 25, 2022

[SOLVED] Two different cURL: second cURL should run right after and only if first cURL is finished running

Issue

I have this:

Running cURL from CodeIgniter (but I don't think it's important)

    $url = "http://example.com/webservice/delete_cURL/".$id;        
    $this->curl->create($url);
    $this->curl->option('buffersize', 10);
    $this->curl->execute();     

    $url = "http://example.com/webservice/save_cURL/".$id;      
    $this->curl->create($url);
    $this->curl->option('buffersize', 10);
    $this->curl->execute();

I need to wait for delete_cURL to finish (some time is longer and it's normal: large folder) before I run the save_cURL Note: The cURLs run to the same server but different URLs


Solution

You propably can use these after your first request to see if was successful at all:

$this->curl->error_code;
$this->curl->error_string;
$this->curl->info;

Additionally, you can print some info (ie. the string "ACK") in the called url and evaluate it like this:

$result = $this->curl->execute();
if ($result == "ACK") {

    // do second request
}


Answered By - Andreas Linden
Answer Checked By - Cary Denson (WPSolving Admin)