Long Polling using jQuery and PHP

后端 未结 1 1185
鱼传尺愫
鱼传尺愫 2021-01-01 06:03

So, I\'ve been trying to do Long-Polling using the jQuery Library and PHP. I\'m doing this so I can make some sort of real-time notifications system in the future. The code

相关标签:
1条回答
  • 2021-01-01 06:39

    Try to use this for ajax.php

    <?php
        if(rand(1, 100) % 2) {
            echo 'even<br />';
        } else {
            sleep(rand(8, 12));
        }   
    ?>
    

    watch this and sometimes you have to wait up to 12 seconds

    if you let him to complete in one second it appears to be broken, but it's not

    0 讨论(0)
提交回复
热议问题