How good does ajax long polling work in PHP?

In my upcoming PHP project, ajax polling ($.get()) is need of the hour and short-polling is something I’ve already ruled out as making server requests every 15 seconds across the internet is futile and waste of bandwidth. However, this polling is an important component of my app as the user gets timely notifications based on that, hence it must never fail. If I implement long-polling with something like this on the PHP side, will it work? (Source )

$time = time();

while ($newestPost <= $time) {
echo "There are new posts available";

In this example, the author calls the sleep function for 10,000 seconds. That’s too long a delay for my use case (as the user needs to access the notifications instantly). If I reduce it to something like 10 or 15 seconds, will it still work?

But Hmm Hmm GIF - But Hmm Hmm But GIFs


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.