I run a server on a shared hosted space (Aruba) with LAMP configuration, with two separate sets of PHP pages, one for the administrator and one for several clients (imagine a quiz game where the administrator submits questions).
I want to achieve this behaviour:
- The administrator presses a button and released the question
- At any time within ten seconds (or even immediately, but not strictly requested) all the clients must display AT THE SAME TIME the page with the text of the question.
To achieve this, I thought of different solutions:
- Web sockets (not feasible, as I cannot install server components on my web page)
- Trigger file generated by the administrator; the clients will periodically (~10 sec) poll (
setInterval()
) for the presence of this file and, depending on the creation time of the file (or an equivalent timestamp read from the file name or file content) the client will start a countdown (setTimeout()
) for the time remaining to when the new page has to be fired, to make sure that all clients eventually trigger at the same time (tenth of second) - Trigger via database (basically same as trigger file, but possibly slower).
I tried the second solution (to manage the reading of trigger file on client-side) both in PHP and in Javascript, but they both fail when there is more than a client connected:
- PHP apparently fails because Apache does not support many simultaneous threads and gets somehow stuck
- Javascript somehow occasionally misses to recognize the presence
of the file in the local directory (with more than one client
connected
XMLHttpRequest.status
incorrectly returns404
even when the trigger file is there) - I even created separate trigger files for the different clients, to make sure there are no concurrency conflicts.
Any hints on why XMLHttpRequest.status
occasionally fails, or advice on a better way of achieving this behaviour?
Thank you in advance.