PHP推荐大活动[关闭]

I've to do a website with a lot of activity and I would to have like your recommendation.

The same page is going to be viewed by 5000 users at the same time... Some data have to be updated every 5 second... each user has different data. so every 5 second : 5000 updates - 5000 SQL query...

I'm not sure ajax is the best way to work... asking the server new data every 5 second is quite heavy...

Is there an onther method to do this? if not, what's your recomandation to improve the website?

Thanks

Well, in what your saying is that you'll have a lot of users requesting a lot of stuff all at once.

The first thing I would do is ensure that you keep regular backups of the database, content and the entire site (code). That way if something does mess up with the massive amounts of requests, you will always have a backup.

The next thing I'd say is ensure you have more than one server running the site which can take a load of each server, so server A can have 2500 people and server B can have 2500 people (for example).

Also, If you ensure that all queries are optimized, I don't think that it really matters that you are going to be using AJAX, it will be 'slow' either way you intend to do it. The best way to counter-act that problem would be to use memcache or some sort of caching utility.

Another point to make would be to ensure that all code is highly optimized and sanitized to prevent as much lag and security issues as possible.

I'm sure you've already heard of it, but you could use "HipHop for PHP" to run your code as C (or C++) instead, which has less of an overhead. That's something I have not personally tried but I hear that it is very good at what it does.

Please let me know if this helps :)

If you need dynamic requests then ajax does the job.

What you want if the server can't handle it is some sort of load balancing (a webserver cluster) and possibly clustered databases as well.

Also make sure that every request is as optimzed as possible, both in the backend calculations, database queries and the amount of data returned to the client.

First of all , you will not have 5k updates at the same times. Your users won't come on your page at the exact same times , so the requests will occurs all the time.

Ajax seems ok to me , you just have to be very careful on your request (don't ask a field if you don't need it for example).

Persistent connection should be a good idea here.

Consider having multiple servers (databases , load balencer ... )

If the only route of the information is database -> web server -> application, then AJAX is the best way of handling it. Requesting only data instead of the entire web page relieves some of the load of your server.

Furthermore, try balancing the load between servers. You can do this using a load balancer, but you could also get your AJAX data from a different server. If this means getting it from a different domain, that's no problem: just use JSONP (http://en.wikipedia.org/wiki/JSONP).