簡體   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