Как я могу ограничить запросы API по одному на пользователя одновременно? - PullRequest
0 голосов
/ 29 января 2019

Я создал сайт для социального маркетинга.Услуги предоставляются API.Когда пользователь запрашивает услугу, API отправляет более одного запроса.Как заставить его запросить услугу только один раз?

public function cron(){
    $orders = Order::where('status', 'Pending')->where('service_no', '!=', 0)->get();
    $api = ApiSetting::first();
    foreach ($orders as $order){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $api->url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS,
            "key=".$api->key."&action=add&service=".$order->service_no."&link=".$order->link."&quantity=".$order->quantity);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $server_output = curl_exec ($ch);
        $item = json_decode($server_output);
        $order->order_no = $item->order;
        $order->save;
        curl_close ($ch);
    }
}

public function cronn(){
    $orders = Order::where('order_no', '!=', 0)->where('service_no', '!=', 0)->get();
    $api = ApiSetting::first();
    foreach ($orders as $order){
        $new_curl = curl_init();
        curl_setopt($new_curl, CURLOPT_URL, $api->url);
        curl_setopt($new_curl, CURLOPT_POST, 1);
        curl_setopt($new_curl, CURLOPT_POSTFIELDS,
            "key=".$api->key."&action=status&order=".$order->order_no);
        curl_setopt($new_curl, CURLOPT_RETURNTRANSFER, true);
        $server_output = curl_exec ($new_curl);
        $item = json_decode($server_output);
        $order->start_count = $item->start_count;
        $order->remains = $item->remains;
        $order->status = $item->status;
        $order->save;
        curl_close ($new_curl);
    }
}
...