API workaround

I had a problem developing a Wordpress plugin. Basically the API I create a plug-in to limit the requests that I need to make to 6 per minute, however, when the plug-in is activated, I need to make more than 6 requests to load the API data that I need for the plugins, in.

API is the LimelightCRM API ( http://help.limelightcrm.com/entries/317874-Membership-API-Documentation ). I am using the campaign_viewAPI method , and what I want to do is potentially make requests in batches, but I'm not quite sure how to approach the problem.

Idea 1: I just think that I will need to calculate the number of requests that I will need to make using PHP to activate the plugin, using campaign_find_active, then divide this number by the request limit (6) and do 6campaign_viewrequests per minute until I have all the data I need and save it in Wordpress transients. However, let's say I need to make 30 requests, the user cannot just sit and wait 5 minutes to download the data. Even if I manage to come up with a solution for this, I may need to set the timelines for Wordpress transients in such a way that the plug-in will never need to complete more than 6 requests. So, my next thought is: can I use the Wordpress hook to make requests every so often, checking when the last batch of requests was executed? So this is already very difficult. I wonder if you guys could point me in the right direction. Do you have any ideas on how I can exceed this limit?

Idea 2: Cron Tasks That Store Values ​​in a Database?

//Fetch Campaign ID's
$t_campaign_find_active = get_transient('campaign_find_active');
if(!$t_campaign_find_active){
    limelight_cart_campaign_find_active();
    $t_campaign_find_active = get_transient('campaign_find_active');
    return $t_campaign_find_active;
}

//Fetch Campaign Information for each Campaign ID
$llc_cnames = array();
foreach($llc_cids as $count => $id) {
    if(!get_transient('campaign_view_'.$id)) {
        limelight_cart_campaign_view($id);
        $llc_cnames[$id] = get_transient('campaign_view_'.$id);
    }
}

//Merge Campaign ID and Campaign Info into Key => Value array
$limelight_campaigns = array_combine($llc_cids, $llc_cnames);

Note. Function limelight_cart_campaign_find_active()and limelight_cart_campaign_view()are not included because they just make one API request, returns a response and keep it in a transient Wordpress. I can include the code if you need it, but for the purposes of this example, this part of the plug-in works, so I did not enable it.

+4
source share
2 answers

, . , API . , , , , , , . , , API, , API AJAX. , .

-, , API, , , API . API.

, " ", " ", AJAX campaign_find_active, ID . .

, , , campaign_view . , . CSS jQuery / AJAX . API , , API , .

Wordpress , . API 1- , , 24 , . , , , . , .

, 3-4 API. , , . - " API 10 , 60 ".

, . , -, API-, AJAX - , .

+2

40 API .

$api_acounts = array(
    "account1" => "asdfasdfdsaf",
    "account2" => "asaasdfasdf",
    "account3" => "asdfasdf",
);
$rand = rand(1,count($api_acounts));
$username = "account".$rand;
$password = $api_acounts['account'.$rand];
Hide result
+2

Source: https://habr.com/ru/post/1547762/


All Articles