Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

293
Vistas
How to handle multiple api calls using php curl
        <?php
    //first api call
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
      CURLOPT_URL => ' firs api url',
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => '',
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 0,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => 'GET',
     
    ));
    
    $response_userdata = curl_exec($curl);
    //first api call response 2 seconds
    $data_userdata=json_decode($response_menutable,TRUE);
    curl_close($curl);

    
    //second api call
           $curl = curl_init();
    
    curl_setopt_array($curl, array(
      CURLOPT_URL => 'seconds api url',
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => '',
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 0,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => 'GET',
     
    ));
    
    $response_stockavldetails = curl_exec($curl);
//second api call response time 2 seconds
    $data_stockavldetails=json_decode($response_stockavldetails,TRUE);
    curl_close($curl);
        
        //Third api call
        $curl = curl_init();
    
    curl_setopt_array($curl, array(
      CURLOPT_URL => 'third api call url',
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => '',
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 0,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => 'GET',
     
    ));
    
    $response_stockoutgoingdetails = curl_exec($curl);
//third api call response time 2 seconds
    $data_stockoutgoingdetails=json_decode($response_stockoutgoingdetails,TRUE);
    curl_close($curl);
           //total response time 6 seconds
    
    ?>

What I am doing

  1. In these above programs I have been calling three API and getting 3 responses using PHP curl
  2. In the first call it has been taking 2 seconds while waiting for a response and then call next API call
  3. Because of that it's taking more than 6 seconds for getting my data and use them

What do i need

  1. I need to get all 3 responses within 2 seconds
  2. I need to know is there a way to call three API at the same time and get responses at the same time
  3. or correct way to handle multiple API call and responses to get data faster

Preferable PHP

javascript fetch throwing cors error if calling API in javascript is faster than PHP suggest me that too I will try

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda