PHP Is it correct to cache MYSQL queries in a txt file?

I am building an online store and trying to improve performance by minimizing MYSQL queries.

Is it good to cache mysql queries through a txt file and then extract this instead of the query? This is what I do. "

  • Php class accept sql query as string
  • does md5 of this
  • if this is the first launch
  • then execute the query in the database
  • get results in an array
  • serialize the array and save it as md5_Of_Query.txt
  • returns either unserialize (file_get_contents (md5_of_Query.txt)) or $ the results of the actual query, depending on whether or not a cache exists.
  • The class also checks the filemtime () of the txt file and, if there is more than one, say one hour, then repeat the request and refresh the cache.

Is this more efficient than executing sql queries every time? Any security issues I'm missing?

+5
source share
8 answers

If you are just starting the application, memcache is a much faster way than using text files.

http://memcached.org/

Text files will do the job, and the steps you outlined make sense, but memcache will be faster and will handle a lot of hard work for you.

+5
source

If you do the test, the cost of creating a unique hash and performing disk I / O will be more than just fetching from a MySQL server.

, , . , MySQL .

, " - ".

+8

, RESTful, , HTTP - . :

  • HTTP- GET URL- , URL
  • php script, URL, , MySql
  • script
  • script
  • - URL-.
  • HTML

PHP Apache . , , , - .

+2

, thephpdeveloper , , / , IO, . , mysql, , , . Memcache , , , .

, / .

+1

: 2, benchmarking profiling. , , - diciplines , mysql, php.ini, httpd.conf,.htaccess, - .

+1

, .

. ( , SQL, , select, join )

. , . ( IO, )

, , - . , , , readfile() .

+1

MySQL ?

0

All Articles