示例#1
0
<?php

function disable_ob()
{
    while (ob_get_level()) {
        ob_end_flush();
    }
}
function flush_buffer()
{
    //Without this str_pad it wont flush :|
    echo str_pad("", 4096, " ");
    echo str_pad("", 4096, " ");
    echo str_pad("", 4096, " ");
    echo str_pad("", 4096, " ");
    flush();
}
disable_ob();
for ($i = 0; $i < $num_subscribers; $i++) {
    $val = $subscribers[$i];
    //mg_send_mail($val['email'], $params);
    $this->database->SubscriberUpdated($val['email']);
    echo "# {$i} Mail sent to : {$val['email']} <br>";
    flush_buffer();
    sleep(1);
}
echo "<br> {$i}  mails sent <br>";
echo "Check Mailgun dashboard for stats.<br>";
示例#2
0
function page_load()
{
    global $CHAT_DATA_FILE_NAME;
    global $CHAT_KEY_LAST_INDEX;
    global $CHAT_CONNECTION_TIMEOUT;
    global $CHAT_KEY_FORMAT;
    global $CHAT_KEY_CALLBACK;
    //chat lines
    $lines = get_lines();
    // How many lines are there in total.
    $lineCount = count($lines);
    // The last sequence number retrieved in that session.
    $lastIndex = get($CHAT_KEY_LAST_INDEX, 0);
    // Used for detecting connection timeout.
    $startTime = $currentTime = time();
    // Used for detecting file changes.
    $startModified = $currentModified = filemtime($CHAT_DATA_FILE_NAME);
    // request format
    $format = get($CHAT_KEY_FORMAT, 'json');
    // calback
    $callback = get($CHAT_KEY_CALLBACK, 'callback');
    $isNewData = $lineCount - 1 > $lastIndex;
    // if there is unread data, flush immediately.
    if ($isNewData) {
        flush_buffer($lines, $lastIndex, $format, $callback);
        die;
    }
    //busy-wait
    while (true) {
        // Give some breathing time for the CPU.
        usleep(10000);
        // Reset file statistics.
        clearstatcache();
        $currentTime = time();
        $currentModified = filemtime($CHAT_DATA_FILE_NAME);
        $isFileModified = $currentModified - $startModified > 0;
        // Someone else has modified the file, get contents and flush.
        if ($isFileModified) {
            $lines = get_lines();
            break;
        }
        $isResponseTimedOut = $currentTime - $startTime > $CHAT_CONNECTION_TIMEOUT;
        // Nothing special, break and give a default response.
        if ($isResponseTimedOut) {
            break;
        }
    }
    flush_buffer($lines, $lastIndex, $format, $callback);
    die;
}