We use cookies
We use cookies to optimize our website. By continuing to browse the site, you agree to our use of cookies.
New design
Control panel
  • Русский
  • Українська
  • English
  • UAH
  • USD
  • RUB
  • EUR
  • 0-800-307-307 Hotline
  • +38 (044) 392-74-33 Kiev
  • +38 (057) 728-39-00 Kharkiv
  • +38 (056) 794-38-31 Dnipro
  • +38 (032) 229-58-93 Lviv
  • +38 (048) 738-57-70 Odessa
  • +38(093) 170-15-42  Life
  • +38 (067) 400-88-44 Kievstar
  • +1(888)393-24-51  USA, Toll free
  • +44(131)507-01-14  Great Britain
  • +7 (499) 348-28-61 Moscow

2.8.1.4. Memcache test (d)

(Requirements: PHP 5.4+)

To test the operation of the Memcache and Memcached modules, you can torun script. After the first launch, the recorded date will be displayed in Memcache and Memcached, if they are loaded, and each subsequent launch will display exactly the time of the first.

For each module, the message “Start memcache(d)».

memcache.php
  1. <?php
  2. if(extension_loaded('memcache')) {
  3. echo "<br>Start memcache<br>";
  4. $memcache = new Memcache();
  5. $memcache->connect('unix:///home/' . explode("/",__DIR__)[2] . '/.system/memcache/socket', 0) or die ("unable to connect");
  6. if (!$memcache->get('int') && !$memcache->get('string') && !$memcache->get('array')) {
  7. $memcache->set('string', 'variables were set at ' . date('F'));
  8. $memcache->set('int', date('d'));
  9. $memcache->set('array', array(date('G'), date('i')));
  10. }
  11. echo $memcache->get('string') . " " . $memcache->get('int') . ", " . $memcache->get('array')[0] . ":" . $memcache ->get('array')[1] . "<br>";
  12. var_dump($memcache->get('int'));
  13. var_dump($memcache->get('string'));
  14. var_dump($memcache->get('array'));
  15. }
  16. if (extension_loaded('memcached')) {
  17. echo "<br>Start memcached<br>";
  18. $m = new Memcached();
  19. $m->addServer('/home/' . explode("/",__DIR__)[2] . '/.system/memcache/socket', 11211);
  20. if (!$m->get('Dint') && !$m->get('Dstring') && !$m->get('Darray')) {
  21. $m->set('Dstring', 'variables were set at ' . date('F'));
  22. $m->set('Dint', date('d'));
  23. $m->set('Darray', array(date('G'), date('i')));
  24. }
  25. echo $m->get('Dstring') . " " . $m->get('Dint') . ", " . $m->get('Darray')[0] . ":" . $m->get('Darray')[1] . "<br>";
  26. var_dump($m->get('Dint'));
  27. var_dump($m->get('Dstring'));
  28. var_dump($m->get('Darray'));
  29. }
  30. ?>