You are talking about a lengthy survey.
A "long survey" is a name used to describe a technique that:
- An AJAX request is executed (using a javascript framework such as jQuery) The server expects the requested data to be available, loops and beds (your server-side PHP script)
- This loop repeats after the data is returned to the client and processed (usually in the AJAX request onComplete callback function)
This essentially simulates a continuous stream in real time from the client to the server. I would not do this in PHP for many reasons. Here is some of them:
- PHP created for fast execution (not for waiting)
- PHP will force you to do some server-side polls and rely on sleep ()
- PHP will feed on your RAM, while spawning processes are for everyone (Apache will do this)
- Do not use the Apache server for this purpose! Apache Server will be better able to handle tens of thousands of short end connections better than a few hundred persistent connections. No matter which direction you go (long poll vs ajax). You might want to consider creating a lighter chat dedicated web server. something like Lighttpd or Nginx, which can have more max_clients or more simultaneous requests under the same memory / CPU conditions.
But you can do this using sleep, polling the database (or, better, the APC / Memcache cache).
If you want to do something like this, go to some technologies that can handle events: Python (Tornado, gevent, eventlet, Twisted, ...), Ruby (Eventmachine, ...), Erlang, Scala, JavaScript on the side server (node.js, ...), comet ...
Instead, you can use a simple way

Take a look at this table.
You can do something like that
Create some db table named for example. log and write some data (e.g. ip, login date ...) when a user visits your site. Leave the signout_date field blank. (when the user subscribes, just refresh this table and put the current date). If someone is on your site, the statement date field should be blank.
Then, in each user action, check your table for user_id : if the number of rows with the same user_id and empty user_id date field is greater. Then simply tell the user that another computer has signed your credentials.
source share