Поддержка Проблемы и решения Мультипоточность cURL через переменную?

  • Есть ряд массивов, которые связаны между собой url

    То есть условно есть Notification List который включает подобный массив

    {
      "data": [{
        "id": 1272,
        "document_symbol": "G\/MA\/QR\/N\/RUS\/5",
        "document_language": "English",
        "period_covered": "2020 - 2022",
        "notification_date": "21\/10\/2021",
        "reporter_member_name": "Russian Federation",
        "reporter_member_code": "C643",
        "hs_class_code": "H6",
        "type": "Complete",
        "details": "https:\/\/qr.wto.org\/api\/v2\/notifications\/1272"
      }],

    В details у него есть ссылка ведущая на следующий массив => Single Notification где по 1272 он определяет, что это Россия

    {
      "data": [{
        "id": 7336,
        "notification_id": 1272,
        "member_name": "Russian Federation",
        "member_code": "C643",
        "document_symbol": "G\/MA\/QR\/N\/RUS\/5",
        "qr_serial_number": 3,
        "qr_group": 961370777,
        "measures": [{
          "symbol": "CP",
          "label": "Prohibition except under defined conditions"
        }, {
          "symbol": "NAL",
          "label": "Non-automatic licensing"
        }, {
          "symbol": "NAL-X",
          "label": "Non-automatic licensing"
        }, {
          "symbol": "CP-X",
          "label": "Prohibition except under defined conditions"
        }],
        "administrative_mechanisms": "Administered by the Federal Service Supervision of Natural Resources (issuance of permits) and Ministry of Industry and Trade of the Russian Federation (issuance of licenses)",
        "national_legal_bases": "Decision of the Board of the Eurasian Economic Commission \u2116 30 of April 21; 2015; as last amended and adjusted",
        "description": "Import and export prohibition and restriction of ozone-depleting substances",
        "period_from_dt": "01\/10\/2020",
        "period_to_dt": "30\/09\/2022",
        "in_force_dt": "01\/10\/2021",
        "details": "https:\/\/qr.wto.org\/api\/v2\/qrs\/7336"
      },

    И тут та же история идет ссылка в том же details на следующий массив https:\/\/qr.wto.org\/api\/v2\/qrs\/7336

    Вопрос стоит в том, что могу ли я в url запроса через curl ставить переменную и делать этот сам запрос через if потому что он должен делать в случае если эта страна в целом есть в этом массиве, если да прошу подсказать как это можно реализовать

    Так же прошу в целом помочь с выводом мультипоточности ибо и так и так не хочет

    $headers2 = array(
       "Accept: application/json",
       "Ocp-Apim-Subscription-Key: 88888888888888",
    );
    
    $ch1 = curl_init("https://api.wto.org/qr/v1/wto-agreements/001?locale=en");
    $ch2 = curl_init("https://api.wto.org/qr/v1/wto-agreements/002?locale=en");
    
    function ex_curl_setopt1($ch1, int $option1, $val1): void
    {
        if (!curl_setopt($ch1, $option1, $val1)) {
            throw new \RuntimeException("curl_setopt failed: " . curl_errno($ch1) . ":" . curl_error($ch1));
        }
    }
    function ex_curl_setopt2($ch2, int $option2, $val2): void
    {
        if (!curl_setopt($ch2, $option2, $val2)) {
            throw new \RuntimeException("curl_setopt failed: " . curl_errno($ch2) . ":" . curl_error($ch2));
        }
    }
    
    curl_setopt($ch1, CURLOPT_HTTPHEADER, $headers2);
    curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch2, CURLOPT_HTTPHEADER, $headers2);
    curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
    
    $mh = curl_multi_init();
    
    curl_multi_add_handle($mh,$ch1);
    curl_multi_add_handle($mh,$ch2);
    
    do {
        $status = curl_multi_exec($mh, $active);
        if ($active) {
            curl_multi_select($mh);
        }
    } while ($active && $status == CURLM_OK);
    
    $data = curl_multi_remove_handle($mh, $ch1);
    $data2 = curl_multi_remove_handle($mh, $ch2);
    
    curl_multi_close($mh);
    
    $data = json_decode($response, true, 999, JSON_THROW_ON_ERROR);
    
    var_dump($response);
    $headers2 = array(
       "Accept: application/json",
       "Ocp-Apim-Subscription-Key: 88888888888888",
    );
    
    $ch1 = curl_init("https://api.wto.org/qr/v1/wto-agreements/001?locale=en");
    $ch2 = curl_init("https://api.wto.org/qr/v1/wto-agreements/002?locale=en");
    
    function ex_curl_setopt1($ch1, int $option1, $val1): void
    {
        if (!curl_setopt($ch1, $option1, $val1)) {
            throw new \RuntimeException("curl_setopt failed: " . curl_errno($ch1) . ":" . curl_error($ch1));
        }
    }
    function ex_curl_setopt2($ch2, int $option2, $val2): void
    {
        if (!curl_setopt($ch2, $option2, $val2)) {
            throw new \RuntimeException("curl_setopt failed: " . curl_errno($ch2) . ":" . curl_error($ch2));
        }
    }
    
    curl_setopt($ch1, CURLOPT_HTTPHEADER, $headers2);
    curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch2, CURLOPT_HTTPHEADER, $headers2);
    curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
    
    $mh = curl_multi_init();
    
    curl_multi_add_handle($mh,$ch1);
    curl_multi_add_handle($mh,$ch2);
    
    do {
        $status = curl_multi_exec($mh, $active);
        if ($active) {
            curl_multi_select($mh);
        }
    } while ($active && $status == CURLM_OK);
    
    curl_multi_remove_handle($mh, $ch1);
    curl_multi_remove_handle($mh, $ch2);
    
    curl_multi_close($mh);
    
    $response1 = curl_multi_getcontent($ch_1);
    $response2 = curl_multi_getcontent($ch_2);
    
    $response1 = json_decode($response, true, 999, JSON_THROW_ON_ERROR);
    
    var_dump($response);
  • Тема «Мультипоточность cURL через переменную?» закрыта для новых ответов.