al-dr
al-dr

Reputation: 147

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 run 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 ?

Upvotes: 0

Views: 341

Answers (2)

drew010
drew010

Reputation: 69927

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.

Upvotes: 0

Aurelio De Rosa
Aurelio De Rosa

Reputation: 22142

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

Upvotes: 1

Related Questions