繁体   English   中英

加快php加载时间

[英]speed php load time up

我有以下php代码:

// Add the unsubscribers to an array
$unsubs = array();
foreach($unsubscribers->response->Results as $entry2) {
    $unsubs[] = $entry2->EmailAddress;
}

// Loop through the subscribers
foreach($result->response->Results as $entry) { 

    echo '<tr class="'. $entry->EmailAddress.'">';      
    echo '<td>'. $entry->EmailAddress.'</td>';
    echo '<td></td><td>';

    // If the subscriber is in our unsubscriber array, output the email again
    if(in_array($entry->EmailAddress, $unsubs)) { 
        echo $entry->EmailAddress;
    }

    echo '</td><td></td>';
    echo '<td></td>';
    echo '<td></td>';
    echo '</tr>';

}

空的<td></td>所在的位置,我想放置以下内容:

$getlists = new CS_REST_Campaigns($_POST['campaign_id'], $auth);
$getlistsresult = $wrap->get_lists_and_segments();
    foreach($getlistsresult->response->Lists as $list) {
        //echo $list->ListID;
    } 

$wrapcount = new CS_REST_Subscribers($list->ListID, $auth);
$resultcount = $wrapcount->get_history($entry->EmailAddress);   


    foreach($resultcount->response as $entrycount) { 

        $counts = array();

foreach($entrycount->Actions as $actions) {
    if(!isset($counts[$actions->Event])) {
        $counts[$actions->Event] = 0;
    }
    ++$counts[$actions->Event];
}


    echo '<td>';
    if ($counts['Click']){echo $counts['Click'];} 
    echo '</td>';

    echo '<td>';
    if ($counts['Bounce']){echo 'Yes';}
    echo '</td>';

    echo '<td>';
    if ($counts['Open']){echo $counts['Open'];} 
    echo '</td>';

    }

这在一定程度上可行,但是页面的加载时间大大增加了。 我认为老实说,我的代码需要整理。 关于如何加快速度的任何建议?

我看不到您的代码中公然未优化的东西,从CS_REST类中有一些我不知道的函数调用,但是我们不知道这些函数的作用或它们是否会变慢或优化。

有了这些信息,我可以看到的唯一对您有所帮助的就是使用SplFixedArray类。 如果您在数组中有很多条目并对它们进行很多操作,这将特别有用。 基本上,它们与实际数组相似,因为它们的索引始终是整数,并且具有固定的大小,这又使它们使用起来更快。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM