开发者

php - which is faster call mysql connection + query OR call a data file?

good evening,

i have a mysql table that contain the users data

and i use mysql_connect, mysql_query, mysql_fetch_array to fetch user data

this query should r开发者_StackOverflow社区un on every page load and for thousands of users

so which is better and faster ? using mysql for every page load ?

OR cache all of the user data results in a file and include it ?


I think the right answer is mix. You should cache the most common query result and retry the other "on the fly"


If it is user data for logged in users, I would store their user info in the session rather than fetching it over and over again.

If it will be changing frequently and you are worried about database performance, a good option would be to cache the data using something like memcached to cache the data in memory. You could request the data from cache on each request, and if user information changes, simply update the cache and the next time it is fetched it will get the new data and there is no need to hit the database unless the cache entry doesn't exist.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜