2.8.1.4. Memcache test (d)

Note

The process of ordering and configuring Memcache (d) is described in instruction.

To test the operation of the Memcache and Memcached modules, you can torun script. The first time you start Memcache and Memcached, if loaded, the date is recorded. On subsequent launches, the date recorded at the first launch is displayed. For each module, if it is correctly loaded and working, a message will be displayed "extension loaded".

  1. <?php
  2. echo 'PHP version: ' . phpversion()."<br>";
  3. $dir = explode("/", $_SERVER["SCRIPT_FILENAME"]);
  4. $account = $dir[2];
  5.  
  6. if (extension_loaded('memcached')) {
  7. echo "<br>MemcacheD extension loaded<br>";
  8. $md = new Memcached();
  9. $md->addServer('/home/' . $account . '/.system/memcache/socket', 11211);
  10. if (!$md->get('Dint')) {
  11. $md->set('Dint', time());
  12. }
  13. echo date("d-m-Y H:i:s", $md->get('Dint'))." - date and time of the first run of the script in memcacheD<br>";
  14. var_dump($md->get('Dint'));
  15. } else {
  16. echo "<br>MemcacheD extension NOT loaded<br>";
  17. }
  18.  
  19. if (extension_loaded('memcache')) {
  20. echo "<br><br>Memcache extension loaded<br>";
  21. $m = new Memcache;
  22. $m->connect('unix:///home/' . $account . '/.system/memcache/socket', 0) or die ("unable to connect");
  23. if (!$m->get('int')) {
  24. $m->set('int', time());
  25. }
  26. echo date("d-m-Y H:i:s",$m->get('int'))." - date and time of the first run of the script in memcache<br>";
  27. var_dump($m->get('int'));
  28. } else {
  29. echo "<br>Memcache extension not loaded<br>";
  30. }
Content