This is how my information is displayed

$count = mysql_result(mysql_query('SELECT COUNT(*) FROM `blog`'), 0); if ($count > 0) { $req = mysql_query("SELECT * FROM `blog` ORDER BY `id` DESC LIMIT " . $start . "," . $message); while ($row = mysql_fetch_assoc($req)) { echo '<b>'.$row['name'].'</b> '.times($row['time']).'<br/>'; if (mb_strlen($row['text']) > 149) { $text = mb_substr($row['text'], 0, 149); echo ''.$text.'...'; } else { echo $row['text']; } echo '<br/><a href="'.$home.'/admin/blog.php?view&amp;id='.$row['id'].'">ΠΏΠΎΠ΄Ρ€ΠΎΠ±Π½Π΅Π΅</a><br/> <a href="'.$home.'/admin/blog.php?edit&amp;id='.$row['id'].'"><input type="submit" value="Ρ€Π΅Π΄Π°ΠΊΡ‚ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ запись"/></a> <a href="'.$home.'/admin/blog.php?del&amp;id='.$row['id'].'"><input type="submit" value="ΡƒΠ΄Π°Π»ΠΈΡ‚ΡŒ запись"/></a> <div id="hr"></div>'; } if ($count > $message) { echo ''.pagenav('?', $start, $count, $message); } } else { echo 'Записи Π΅Ρ‰Π΅ Π½Π΅ созданы!'; } 

And how to make the output of information using memkes? For information to be cached, say, for half an hour.

  • For the future - format the code, please, otherwise nothing is visible in this jumble. You show people, after all ... - drdaeman

2 answers 2

 // ΠΊΠ°ΠΊΠΎΠΉ мСмкСш ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚Π΅ Π½Π΅ΠΏΡ€ΠΈΠ½Ρ†ΠΈΠΏΠΈΠ°Π»ΡŒΠ½ΠΎ, // Ρ‡ΡƒΡ‚ΡŒ ΠΎΡ‚Π»ΠΈΡ‡Π°ΡŽΡ‚ΡΡ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Ρ‹, ΠΏΡ€ΠΈΠ½Ρ†ΠΈΠΏ Ρ‚ΠΎΡ‚ ΠΆΠ΅ остаСтся. // Memcached Ρ‡ΡƒΡ‚ΡŒ ΠΌΠ΅Π΄Π»Π΅Π½Π½Π΅Π΅ Memcache Π² синтСтичСских тСстах $memcache = new Memcached(); // ΠΈΠ½Ρ‚Π΅Ρ€Π²Π°Π» ΠΊΡΡˆΠΈΡ€ΠΎΠ²Π°Π½ΠΈΡ $cache_interval = 1800; //соСдиняСмся $memcache->addServer('localhost', 11211) or die ("Could not connect to memcached"); //ΠΏΠ΅Ρ€Π²Ρ‹ΠΉ запрос $query = 'SELECT COUNT(*) FROM `blog`'; //ΠΊΠ»ΡŽΡ‡, ΠΏΠΎ ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΌΡƒ Π±ΡƒΠ΄Π΅ΠΌ ΠΈΡΠΊΠ°Ρ‚ΡŒ этот запрос Π² мСмкСшС $key = "blog_count"; $count = $memcache->get($key); if($count === false) { // Π½Π΅ нашли Π² мСмкСшС, Π±Π΅Ρ€Π΅ΠΌ ΠΈΠ· Π±Π°Π·Ρ‹ $count = mysql_result(mysql_query($query), 0); //складываСм Π² мСмкСш $memcache->set($key,$result,$cache_interval); } if($count>0) { // Π²Ρ‚ΠΎΡ€ΠΎΠΉ запрос $query = "SELECT * FROM `blog` ORDER BY `id` DESC LIMIT " . $start . "," . $message; // ΠΊΠ»ΡŽΡ‡ для мСмкСша этого запроса $key = md5('query'.$query); //ΠΈΡ‰Π΅ΠΌ Π² мСмкСшС этот запрос $rows = $memcache->get($key); // нашли? if ($rows === false) { // Π½Π΅ нашли, Ρ‡ΠΈΡ‚Π°Π΅ΠΌ ΠΈΠ· Π±Π°Π·Ρ‹ Π² массив $rows $rows = array(); $req = mysql_query($query); while ($row = mysql_fetch_assoc($req)) { $rows[] = $rec; } // пишСм Π² мСмкСш $memcache->set($key, $rows, $cache_interval); } // Ρ€Π°Π±ΠΎΡ‚Π°Π΅ΠΌ с массивом ΠΊΠ°ΠΊ Ρ€Π°Π½ΡŒΡˆΠ΅ foreach($rows as $row) { // ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌ $row ΠΊΠ°ΠΊ Ρ€Π°Π½ΡŒΡˆΠ΅... ... 

Threat wrote in the answer window, errors are possible

  • true say, the page can also be cached. Well, let it be as an option to work with memkes ... - Yura Ivanov
  • And who and how dumps memcache when changing data in the blog table? - avp
  • time :) is one of the options. the simplest. Yes, you can change the cache with changes, but it seems that half an hour the weather does not. it all depends on the task. - Yura Ivanov
  • Yura Ivanov, not working. Records are not displayed. - vitagame
  • one
    Judging by the initial question and talking about half an hour, the vehicle apparently understands that the changes will be frozen for half an hour for visitors who are ridonly. For authors of the blog who want to make any changes, this approach is naturally not suitable. those who can change the content either have to work directly with the database (without the cache), or have to modify the cache for each update or delete in the database. @vitagame not connecting to server? or the data is not stored in the cache? the fact that the records are not displayed is already a result, you need to watch what happens at each stage (connection, het, set ...) - Yura Ivanov

In Hindu - for example, like this:

 $mc = new Memcache; $mc->connect(...); ... $key = "blog/by-id[$start,$message]"; $html = $mc->get($key); if ($html === false) { ob_start(); $req = mysql_query("SELECT * FROM `blog` ORDER BY `id` DESC LIMIT " . $start . "," . $message); while ($row = mysql_fetch_assoc($req)) { // ... } $html = ob_end_clean(); $mc->set($key, $html); } 

But this is not a code, but rubbish.

In the mind - to spread the model and the view, the fragment cache to implement at the template level, the data cache - at the model level (mixin or decorator). In order not to reinvent the wheel, take a ready-made framework that will do everything on its own.

  • Thanks for answers. For example, what kind of framework? - vitagame