duanpin9531 2016-05-07 07:01
浏览 19

加快PHP通话速度

so I have some PHP code which is displaying an email list (Name, Surname & Email) from a list I have hosted via API.

The problem I have is that in order to display the name of the subscriber, I have to separately pass the email through the API... and the only way to get the email is to use a separate function.

So, for a list of 100 people, I'm basically hitting calling their API 300 times... so it is taking forever to echo the information (and over 30ish people the server just times out).

Is there a way I can edit the blow code so that I'm not pulling their info EVERY time, and instead bring it all down at once?

Here's my code:

<?php

        require('Mailin.php');

/////////Total Subscriber Count  $subscribers
        $mailin = new Mailin('https://api.sendinblue.com/v2.0','UNIQUEKEY');

        $datacount = array( "id"=>13 );
        $subscribercount = $mailin->get_list($datacount);
        $subscribers = $subscribercount['data']['total_subscribers'] - 1;

/////////Get Emails of Subscribers
        $dataemail = array( "listids" => array(2),
                        "page" => 1,
                        "page_limit" => 500
        );
        $getemails = $mailin->display_list_users($dataemail);

/////////Get Name of Subscribers
        foreach (range(0, $subscribers) as $number) {
            $subscriberemail = $getemails['data']['data'][$number]['email'];
                    echo $subscriberemail;
                    echo '<br/>';

                    $dataname = array( "email" => $subscriberemail );
                    $getname = $mailin->get_user($dataname);
                        $subscribername = $getname['data']['attributes']['NAME'];
                        $subscribersurname = $getname['data']['attributes']['SURNAME'];

                        echo $subscribername;
                        echo '<br/>';
                        echo $subscribersurname;
                        echo '<br/>';
        }

?>

Here is the output you get calling the display_list_users:

{ 
  "code":"success",
  "message":"Retrieved details of all users for the given lists",
  "data":{
      "data":[
        {
          "blacklisted":0,
          "email":"email1@domain.com",
          "id":1,
          "listid":[1],
          "blacklisted_sms":1,
          "last_modified" : "2015-05-22 15:30:00"
        },
        {
          "blacklisted":1,
          "email":"email2@domain.com",
          "id":2,
          "listid":[1,2],
          "blacklisted_sms":0 ,
          "last_modified" : "2015-05-25 19:10:30"        
        }
      ],
  "page":1,
  "page_limit":2,
  "total_list_records":100
  }
}

And the output you get calling the get_user:

{
   "code":"success",
   "message":"Data retrieved for email",
   "data":{
      "attributes":{
         "EMAIL":"example@example.net",
         "NAME" : "Name",
         "SURNAME" : "surname"
      },
      "blacklisted":1,
      "email":"example@example.net",
      "entered":"2014-01-15",
      "listid":[8],
      "message_sent":[{ 
            "camp_id" : 2,
            "event_time" : "2013-12-18"
          },
          { "camp_id" : 8,
            "event_time" : "2014-01-03"
          },
          { "camp_id" : 11,
            "event_time" : "2014-01-07"
          }],
      "hard_bounces":[{ 
            "camp_id" : 11,
            "event_time" : "2014-01-07"
          }],
      "soft_bounces":[],
      "spam":[{ 
            "camp_id" : 2,
            "event_time" : "2014-01-09"
          }],
      "unsubscription":{
         "user_unsubscribe":[
            {
               "event_time":"2014-02-06",
               "camp_id":2,
               "ip":"1.2.3.4"
            },
            {
               "event_time":"2014-03-06",
               "camp_id":8,
               "ip":"1.2.3.4"
            }
         ],
         "admin_unsubscribe":[
            {
               "event_time":"2014-04-06",
               "ip":"5.6.7.8"
            },
            {
               "event_time":"2014-04-16",
               "ip":"5.6.7.8"
            }
         ]
      },
      "opened":[{ 
            "camp_id" : 8,
            "event_time" : "2014-01-03",
            "ip" : "1.2.3.4"
          }],
      "clicks":[],
      "transactional_attributes":[
         {
            "ORDER_DATE":"2015-07-01",
            "ORDER_PRICE":100000,
            "ORDER_ID":"1"
         },
         {
            "ORDER_DATE":"2015-07-05",
            "ORDER_PRICE":500000,
            "ORDER_ID":"2"
         }
      ],
      "blacklisted_sms":1
   }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据