0

私は次の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>';

    }

これはある程度機能しますが、ページの読み込み時間が大幅に増加します。正直なところ、コードを整理する必要があると思います。これをスピードアップする方法に関する提案はありますか?

4

1 に答える 1

1

あなたのコードで露骨に最適化されていないことはあまりわかりません.CS_RESTクラスからの、私が知らない関数呼び出しがありますが、これらの関数が何をするのか、または遅いまたは最適化される可能性があるかどうかはわかりません.

この情報があれば、SplFixedArrayクラスを使用することだけが役に立ちます。これは、配列に多くのエントリがあり、それらに対して多くの操作を行う場合に特に役立ちます。基本的に、インデックスは常に整数であり、サイズが固定されているため、使用が高速になるという点で、実数配列に似ています。

于 2013-07-17T14:31:00.470 に答える