PHP query caching for mySQL performance

I am looking for a system for caching an already encoded project (with PHP) that has features such as a registration system, etc.

I was looking for some caching solutions, but I read that the login system and wiring does not work if I use such functions.

I really need to store the results of some special database queries, if there is a cache, call this if you do not generate a new cache, and re-cache them every x minutes. (results can be saved in txt, etc.).

How can i do this?

By the way, setting query_cache_type to 1 does not work. I am looking for alternative solutions.

thanks

+9
source share
4 answers

Basically you need to cache the request:

# After: [with memcache] $rSlowQuery = mysql_query_cache($sql); # $rSlowQuery is an array $rows = count($rSlowQuery); for ($i=0;$i<$rows;$i++) { } 
+9
source

Reduce database calls Check phpFastCache , which supports WinCache, MemCache, files, X-Cache, APC Cache. It is easy for beginners.

PHP caching class for the database: your site has 10,000 online visitors and your dynamic page must send 10,000 identical database requests each time the page loads. With phpFastCache, your page sends only 1 database request and uses the cache to serve 9999 other visitors.

 <?php // In your config file include("php_fast_cache.php"); // This is Optional Config only. You can skip these lines. // phpFastCache support "apc", "memcache", "memcached", "wincache" ,"files", "pdo", "mpdo" and "xcache" // You don't need to change your code when you change your caching system. Or simple keep it auto phpFastCache::$storage = "auto"; // End Optionals // In your Class, Functions, PHP Pages // try to get from Cache first. $products = phpFastCache::get("products_page"); if($products == null) { $products = YOUR DB QUERIES || GET_PRODUCTS_FUNCTION; // set products in to cache in 600 seconds = 10 minutes phpFastCache::set("products_page",$products,600); } foreach($products as $product) { // Output Your Contents HERE } ?> 
+5
source

I recently encountered a similar problem, and here's how I solved it ...


Step 1: Add the .user.ini file to the .user.ini directory of your project (if you do not already have one) and the following directives to the file to enable the mysqlnd_qc plugin and set the TTL for the cache:

 ; Enables MySQL query caching by PHP mysqlnd_qc.enable_qc = 1 ; Set a default TTL for the caching in seconds mysqlnd_qc.ttl = 30 

Step 2: Add an SQL prompt before any query that you want to cache using mysqlnd_qc.

Here is a tip that should be added to the request:

 "/*" . MYSQLND_QC_ENABLE_SWITCH . "*/" . 

Here is a usage example:

 $res = $mysqli->query("/*" . MYSQLND_QC_ENABLE_SWITCH . "*/" . "SELECT id FROM test WHERE id = 1"); 

That should do it! You can also cache all queries using the mysqlnd_qc.cache_no_table = 1 directive.

All this comes from the PHP documentation, here: http://php.net/manual/en/mysqlnd-qc.quickstart.caching.php

Hope this helps!

+3
source

You can try the following:

 $mysqli -> query("/*qc=on*/ SELECT * FROM table"); 
+1
source

All Articles