加快PHP通话速度

时间:2016-05-07 07:01:42

标签: php api variables

所以我有一些PHP代码,它显示了我通过API托管的列表中的电子邮件列表(姓名,姓氏和电子邮件)。

我遇到的问题是,为了显示订阅者的姓名,我必须通过API单独传递电子邮件...而获取电子邮件的唯一方法是使用单独的功能。

所以,对于一个100人的列表,我基本上打他们的API 300次...所以它需要永远回应信息(超过30人的服务器只是超时)。

有没有办法可以编辑打击代码,这样我就不会每次都把它们的信息拉出来,而是立刻将它们全部拉下来?

这是我的代码:

<?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/>';
        }

?>

以下是您调用 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
  }
}

您输出的输出是 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 个答案:

没有答案