问题原文
原帖链接 · Matthias Pitscher · CC BY-SA 3.0
I want to build a website that only one person at a time can visit. How would I accomplish this task?
I looked at Web counters built in php, but I don't think this is the right solution. Is there an http request for this?
Thank you in advance.
已采纳解答
原帖链接 · L Martin · CC BY-SA 3.0
If you're looking to only serve content to one person at a time, this would be a server level mod. As an example for Nginx, you'd limit the number of active connections to 1:
server { limit_conn perserver 1; }
This serves a 503 error to anyone else that connects. It is possible to serve a custom page with the 503 error, alerting the user as to why they've received it.
If this doesn't suit your needs, you need to serve content to everyone but gate the 'real' content so that only one user at a time can view it. You'd create a page that everyone downloads with an embedded AJAX script. The script makes an API call to your server, asking if the 'page' is occupied. When it's not, the server assigns that page to the user session and returns the content. The script would then display this. Those not currently on the 'page' would be served a waiting page and continue to poll. This would also allow you to form an orderly queue on your server's side too.
Going into that territory, you're better off posting on Stackoverflow to ask how to make such a script.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
