Long Polling with Ajax and PHP - Apache freezes -
we try implement long-polling based notification service in our company's erp. similar facebook notifications.
technologies used:
- php
timeout
set 60 seconds , 1 secondsleep
in each iteration of loop. - jquery ajax handling.
- apache web server.
after month of coding, went production. few minutes after deployment had rollback everything. turned out our server (8 cores) couldn't handle long requests 20 employees, using ~5 browser tabs each. example: user opened 3 tabs our erp, 1 long-polling ajax on each tab. opening 4th tab impossible - hangs until 1 of previous 3 killed (and therefore ajax stopped).
'apache limitations', thought. went googling. found info apache's mpm modules , configs, gave try. our server use prefork
mpm, apachectl -l
shown us. changed few lines in config this:
<ifmodule mpm_prefork_module> startservers 1 minspareservers 16 maxspareservers 32 serverlimit 50% maxclients 150 maxclients 50% maxrequestsperchild 0 </ifmodule>
funny thing is, works on local machine similar config. on server, looks apache ignores config, because minspareservers
set 16, lauches 8 after restart. whe have no idea do.
passerby in first comment of previous post gave me direction check out if hit max browser connections 1 server.
as turns out, each browser has limit , can't change them (as far know). made workaround make work.
let's assume getting ajax
data
http://domain.com/ajax
to avoid hitting max browser connections, each long-polling ajax
connects random subdomain, like:
http://31289.domain.com/ajax http://43289.domain.com/ajax
and on. there's wildcard on dns server pointing *.domain.com
domain.com
, , subdomain unique random number, generated js on each tab.
for more information, check out this thread.
there's been problems ajax same origin security
, managed work out, using appropriate headers on both js
, php
sides.
if want know more headers, check out here on stackoverflow, , here on mozilla developer's page. thanks!
Comments
Post a Comment