この投稿を見つけたばかりですが、古いですが、ポーリングの概念は多くの人に問題を引き起こします. ということで実装例を載せておきます。しかし、その前に、少し前に私を怒らせたアドバイスをしなければなりません。
ポーリングするときは、セッションの動作 (競合状態)に注意する必要があります。簡単にするために:セッションを開くと、セッションが閉じられるまでセッションファイルがロックされ、2つのスレッドが異なるデータを書き込むのを防ぎます。そのため、ユーザーがログに記録されているかどうかを確認するセッションが必要な場合は、ポーリングの前に常にセッションを閉じてください。
私のデモでは、PHP でのポーリングの実装例を示します。データベースではなくファイルを使用します。ポーリング ボタンをクリックするとループに入り、ファイルが変更されるまでポーリングを続けます。フォームに入力してリリースをクリックすると、入力した内容がファイルに保存されます。ファイルの変更時刻が変更されるため、ポーリングが停止します。
ヒント: Firebugなどのツールを使用して、何が起こっているかを確認してください。
では、私の英語よりも良い言語で話しましょう :
<?php
    // For this demo
    if (file_exists('poll.txt') == false) {
        file_put_contents('poll.txt', '');
    }
    if (isset($_GET['poll'])) {
        // Don't forget to change the default time limit
        set_time_limit(120);
        date_default_timezone_set('Europe/Paris');
        $time = time();
        // We loop until you click on the "release" button...
        $poll = true;
        $number_of_tries = 1;
        while ($poll)
        {
            // Here we simulate a request (last mtime of file could be a creation/update_date field on a base)
            clearstatcache();
            $mtime = filemtime('poll.txt');
            if ($mtime > $time) {
                $result = htmlentities(file_get_contents('poll.txt'));
                $poll = false;
            }
            // Of course, else your polling will kill your resources!
            $number_of_tries++;
            sleep(1);
        }
        // Outputs result
        echo "Number of tries : {$number_of_tries}<br/>{$result}";
        die();
    }
    // Here we catch the release form
    if (isset($_GET['release']))
    {
        $data = '';
        if (isset($_GET['data'])) {
            $data = $_GET['data'];
        }
        file_put_contents('poll.txt', $data);
        die();
    }
?>
<!-- click this button to begin long-polling -->
<input id="poll" type="button" value="Click me to start polling" />
<br/><br/>
Give me some text here :
<br/>
<input id="data" type="text" />
<br/>
<!-- click this button to release long-polling -->
<input id="release" type="button" value="Click me to release polling" disabled="disabled" />
<br/><br/>
Result after releasing polling :
<div id="result"></div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
// Script to launch polling
$('#poll').click(function() {
    $('#poll').attr('disabled', 'disabled');
    $('#release').removeAttr('disabled');
    $.ajax({
        url: 'poll.php',
        data: {
            poll: 'yes' // sets our $_GET['poll']
        },
        success: function(data) {
            $('#result').html(data);
            $('#poll').removeAttr('disabled');
            $('#release').attr('disabled', 'disabled');
        }
    });
});
// Script to release polling
$('#release').click(function() {
    $.ajax({
        url: 'poll.php',
        data: {
            release: 'yes', // sets our $_GET['release']
            data: $('#data').val() // sets our $_GET['data']
        }
    });
});
</script>
ここで試すことができます