php_nub_qq Posted May 6, 2013 Share Posted May 6, 2013 Hello, I built myself a small long-polling type system to fetch data from a database dynamically or in other words a chat. But there is a problem. Instead of sending and receiving empty requests I thought I should create an infinite loop upon a request from the client side and only return when there is new data ( new message ). Not knowing why it doesn't work, but if I remove the loop and do it the old fashion way with thousand requests it works, see the code below This doesn't work while(1==1){ sleep(1); require('getMessages.php'); // Fetches new messages and returns them - this works there's no problem here if(!empty($messagesOutput)){ break; } } This works and echoes the text, so the variable is filled when new data is fetched while(1==1){ sleep(1); require('getMessages.php'); if(!empty($messagesOutput)){ echo "TEST TO SEE IF VARIABLE IS FILLED"; } break; } Link to comment https://forums.phpfreaks.com/topic/277703-polling-data-doesnt-work/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.