Making non blocking wp_remote_get requests

Viewed 14

I use wp_remote_get to get the id of products from another eshop via the woocommerce api. What i want is to make the get request non blocking so that the page doesnt crash when there are to many calls to the api. From a research i found out that u can using blocking => false, but it is not working. Can anyone help me? This is my code for the get request.

function get_sku_by_id($product_id) {
    $live_ck = 'ck_XXXXX';
   $live_cs = 'cs_XXXXXXX';
   $product_info = wc_get_product( $product_id );
   $product_info_data = $product_info->get_data();
   $sku = $product_info_data['sku'];
   $live_urls = 'https://isocks.gr/wp-json/wc/v3/products/?consumer_key=' . $live_ck . '&consumer_secret=' . $live_cs .'&sku=' . $sku ;

   $get_response = wp_remote_get( $live_urls,
       array(
          'blocking' => false, 
          'headers' => array( 'Content-Type' => 'application/json' ),
          'timeout' => 30,


       )

    );
    $nodoBody = json_decode($get_response["body"]);
    if ( !is_array ( $nodoBody ) || empty( $nodoBody )) {
        return false;
    }
    else {
    $id_of_prod = $nodoBody[0]->id;
    return $id_of_prod;
    }

}

0 Answers
Related