long-polling


Cannot implement long polling


if(isset($_GET['actionid']) && isset($_GET['profileid']))
{
$actionid = $_GET['actionid'];
$profileid = $_GET['profileid'];
$res = $database->news_poll($profileid,$actionid);
$k = 0;
while(!$NROW =$res->fetch_array())
{
usleep('50000000');
$res = $database->news_poll($profileid,$actionid);
}
$action = actiontype_encode($NROW,'0',$json,$encode,$database);
$data['action'] = $action;
echo json_encode($data);
}
this is my script for polling the server for new data.
but the working browser stops working only for my site. I guess the problem is that when a particular browser subscribes for the new data the connection is kept open so no further request can be made by the browser to same server. please explain if any problem.
If there is any way at all you can, I recommend setting yourself up with NodeJS and SocketIO for long polling. Your web server needs to keep a request open for every connected user, and that is more than Apache/PHP can handle for very long.
If that's not possible I recommend short polling, doing a normal ajax request every 3 seconds. That's not perfect but manageble.
I answered a similar question recently with more details.
Regardless of language I strongly advise against writing your own long polling server, unless you want that to be your project for a couple of years. I have been in a project that used a home grown long polling server written C and then re-written in Java, and it was not pretty.
I figured out the problem is that Apache serves multiple requests from a single client one at a time. So when a request is made to the long polling script at backend for new data that request hangs other requests from the same browser to the same server.
To overcome this drawback one needs to use node.js or tornado.

Related Links

Koa 2 router how to make a long poll request
Confluent long polling properties in kafka-rest
How to combine async and blocking requests in VuGen?
Long polling confusion
WAS Liberty & Atmosphere long-polling 1 min delay
Long Polling interval in atmosphere
MQTT long polling over GPRS/HSDPA
JS and CSS file fails to load when the page is refreshed in grails application which uses Atmosphere Meteor plugin
Security concerns in long polling
Kafka long polling
How to build the request for a long poll url for box.com
how to access enterprise events using Java code
Handle client timeouts when serving long polling with gevent
Long polling blocking multiple windows?
Long polling on a penny auction site?
Cannot implement long polling

Categories

HOME
variables
listview
openmp
smarty
stock
platform-builder
sqlite-net-extensions
cakephp-2.5
jpeg
ojdbc
synchronization
google-translate
node-pdfkit
mapserver
qt-creator
ibm-odm
solaris-10
reactive-cocoa
alpine
physics-engine
sox
microsoft-r
firebase-crash-reporting
xacml
gsmcomm
oracle-fusion-middleware
caret
textmate
sequential
io-redirection
vxworks
xcode-extension
event-driven
impersonation
splice
leading-zero
elasticsearch-plugin
hp-ux
pdf-reactor
http-redirect
skeleton-css-boilerplate
flickr-api
appcompat
hibernate-tools
react-scripts
paxos
hls.js
tropo
colorama
snmptrapd
np-complete
iso8601
messenger
watchconnectivity
jquery-filter
wdf
angular-cache
bstr
jwplayer7
blackberry-10
jfugue
hsv
spim
prerequisites
endeca-workbench
feedback
wordml
wyam
php-ci
myo
apache-commons-fileupload
npapi
modalpopup
gwidgets
nstableviewcell
codeigniter-url
asp.net-web-api-odata
castle
elliptic-curve
transcoding
centos5
quantlib-swig
back-stack
spring-validator
chuck
bitsharp
mt
rdoc
manchester-syntax
dbproviderfactories
whoosh
blackberry-playbook
infobox
calling-convention
disclosure
telerik-scheduler
dentrix
uimenucontroller
procedural-music

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App