Page MenuHomeIn-Portal Phabricator

INP-1750 - Support PHP Memcached extension for caching
ClosedPublic

Authored by erik on Oct 30 2018, 10:59 AM.

Details

Summary

Added memcached support.

Test Plan

Part 1 (general test on PHP5)

  1. confirm, that Memcached service is installed and started on the server
  2. restart Memcached service
  3. re-install In-Portal and on "Step 11 - System Configuration" confirm, that option "Memcached (via "Memcache" extension)" is available choice for "Output Caching Engine" dropdown.
  4. choose this option.
  5. login to Administrative Console
  6. go to ToolsSystem Tools section
  7. confirm, that "Memory Cache" sub-section is visible

Part 2 (general test on PHP7)

  1. confirm, that Memcached service is installed and started on the server
  2. restart Memcached service
  3. re-install In-Portal and on "Step 11 - System Configuration" confirm, that option "Memcached (via "Memcached" extension)" is available choice for "Output Caching Engine" dropdown.
  4. choose this option.
  5. login to Administrative Console
  6. go to ToolsSystem Tools section
  7. confirm, that "Memory Cache" sub-section is visible
NOTE: Perform following tests twice - once after Part 1 installation, and once after Part 2 installation.

Preparation for following tests

  1. create /memcache_test.php file with following content:
<?php
<?php
$start = microtime(true);

define('FULL_PATH', realpath(dirname(__FILE__)));
include_once(FULL_PATH.'/core/kernel/startup.php');

$application =& kApplication::Instance();
$application->Init();

echo 'PHP ' . PHP_VERSION . '<br/><br/>';

switch ( $application->GetVar('step') ) {
    case 'delete':
        echo 'Deleting Infinite Key<br/>' . PHP_EOL;
        $application->deleteCache('infinite_key');

        echo 'Deleting Expiring Key<br/>' . PHP_EOL;
        $application->deleteCache('expiring_key');

        echo 'Deleting Infinite Added Key<br/>' . PHP_EOL;
        $application->deleteCache('infinite_added_key');

        echo 'Deleting Expiring Added Key<br/>' . PHP_EOL;
        $application->deleteCache('expiring_added_key');
        break;

    case 'set':
        $result = $application->setCache('infinite_key', 'infinite value');
        echo 'Setting Infinite Key: ';
        var_dump($result);

        $result = $application->setCache('expiring_key', 'expiring value', 30);
        echo 'Setting Expiring Key: ';
        var_dump($result);

        $result = $application->addCache('infinite_added_key', 'infinite added value');
        echo 'Adding Infinite Adding Key: ';
        var_dump($result);

        $result = $application->addCache('expiring_added_key', 'expiring added value', 30);
        echo 'Adding Expiring Adding Key: ';
        var_dump($result);
        break;

    default:
        echo 'Getting Infinite Key:' . PHP_EOL;
        var_dump($application->getCache('infinite_key'));

        echo 'Getting Expiring Key:' . PHP_EOL;
        var_dump($application->getCache('expiring_key'));

        echo 'Getting Infinite Added Key:' . PHP_EOL;
        var_dump($application->getCache('infinite_added_key'));

        echo 'Getting Expiring Added Key:' . PHP_EOL;
        var_dump($application->getCache('expiring_added_key'));
        break;
}

$end = microtime(true);
  1. this is URL for showing: .../memcache_test.php?step=show
  2. this is URL for setting: .../memcache_test.php?step=set
  3. this is URL for deleting: .../memcache_test.php?step=delete

Part 3 (no cached value by default)

  1. open showing URL couple of times
  2. confirm, that output is similar to this:
PHP ...

Getting Infinite Key:

boolean false

Getting Expiring Key:

boolean false

Getting Infinite Added Key:

boolean false

Getting Expiring Added Key:

boolean false

Part 4 (value is persistent upon setting/adding)

  1. open setting URL
  2. confirm, that output is similar to this:
PHP ...

Setting Infinite Key:

boolean true

Setting Expiring Key:

boolean true

Adding Infinite Adding Key:

boolean true

Adding Expiring Adding Key:

boolean true
  1. open setting URL
  2. confirm, that output is similar to this:
PHP ...

Setting Infinite Key:

boolean true

Setting Expiring Key:

boolean true

Adding Infinite Adding Key:

boolean false

Adding Expiring Adding Key:

boolean false
  1. open getting URL couple of times
  2. confirm, that output is similar to this:
PHP ...

Getting Infinite Key:

string 'infinite value' (length=14)

Getting Expiring Key:

string 'expiring value' (length=14)

Getting Infinite Added Key:

string 'infinite added value' (length=20)

Getting Expiring Added Key:

string 'expiring added value' (length=20)
  1. wait 35 seconds (because auto-expiration is set to 30 seconds)
  2. open getting URL couple of times
  3. confirm, that output is similar to this:
PHP ...

Getting Infinite Key:

string 'infinite value' (length=14)

Getting Expiring Key:

boolean false

Getting Infinite Added Key:

string 'infinite added value' (length=20)

Getting Expiring Added Key:

boolean false
  1. open deleting URL
  2. open showing URL couple of times
  3. confirm, that output is similar to this:
PHP ...

Getting Infinite Key:

boolean false

Getting Expiring Key:

boolean false

Getting Infinite Added Key:

boolean false

Getting Expiring Added Key:

boolean false

Diff Detail

Repository
rINP In-Portal
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

erik created this revision.Oct 30 2018, 10:59 AM
alex added a project: Restricted Project.Nov 1 2018, 6:20 AM
alex requested changes to this revision.Nov 1 2018, 6:38 AM

Test plan requested updates:

  • cover auto-usage of Memcached on PHP 7+, when Memcache is configured to be used
  • cover usage of new caching backend (all public methods via corresponding kApplication facade methods (e.g. MemcachedCacheHandler::add maps to kApplication::addCache and so on)

I'm not able to test any further, because all data set to cache will auto-expire immediately.

core/install/install_toolkit.php
973–975 ↗(On Diff #875)

Please reformat to have one array element on one line.

core/kernel/utility/cache.php
107 ↗(On Diff #875)

Please replace

version_compare(PHP_VERSION, '7.0.0', '>=')

with

PHP_VERSION_ID >= 70000

Works faster.

835 ↗(On Diff #875)

I doubt, that class name used in Memcached PHP extension matches class name used in Memcache PHP extension.

905 ↗(On Diff #875)

Please pass argument according to method signature:

  • Memcache::set( string $key , mixed $var [, int $flag [, int $expire ]] )
  • Memcached::set( string $key , mixed $value [, int $expiration ] )

The value of $expiration parameter is ignored.

921 ↗(On Diff #875)

Please pass argument according to method signature:

  • Memcache::add( string $key , mixed $var [, int $flag [, int $expire ]] )
  • Memcached::add( string $key , mixed $value [, int $expiration ] )

The value of $expiration parameter is ignored.

This revision now requires changes to proceed.Nov 1 2018, 6:38 AM
erik updated this revision to Diff 878.Nov 5 2018, 4:55 AM
erik edited edge metadata.

Made requested code fixes. TODO - test plan changes.

erik edited the test plan for this revision. (Show Details)Nov 7 2018, 4:59 AM
alex edited the test plan for this revision. (Show Details)Nov 7 2018, 7:11 AM
alex requested changes to this revision.Nov 8 2018, 1:45 AM
In D351#6952, @alex wrote:

Test plan requested updates:

  • cover auto-usage of Memcached on PHP 7+, when Memcache is configured to be used
  • cover usage of new caching backend (all public methods via corresponding kApplication facade methods (e.g. MemcachedCacheHandler::add maps to kApplication::addCache and so on)

    I'm not able to test any further, because all data set to cache will auto-expire immediately.

2nd half of requested test plan updates weren't made.

This revision now requires changes to proceed.Nov 8 2018, 1:45 AM
erik requested review of this revision.Nov 8 2018, 4:25 AM
erik edited the test plan for this revision. (Show Details)
erik edited edge metadata.
alex added a comment.Nov 8 2018, 5:08 AM

Not reopening, but test plan have issues:

  • not tested, that data is actually persistent in Memcache (e.g. available on different page loads)
  • not tested, that data in Memcache expires at given moment of time
alex updated this revision to Diff 885.EditedNov 13 2018, 8:01 AM
alex edited the test plan for this revision. (Show Details)

Fixed API difference causing a notice (and non-working cache), when attempting to get several keys at once using get method.

alex updated this revision to Diff 886.Nov 13 2018, 8:03 AM

Removed test file.

alex edited the test plan for this revision. (Show Details)Nov 13 2018, 8:31 AM
alex accepted this revision.Nov 13 2018, 8:36 AM
This revision is now accepted and ready to land.Nov 13 2018, 8:36 AM
alex requested changes to this revision.EditedJan 15 2021, 8:56 AM

This change isn't a bug fix request, but a requirement change, that happened over time.

Please also update the test plan.

core/kernel/utility/cache.php
107–109 ↗(On Diff #886)
  1. move the code, that creates cache handler object (with fallback to the fake cache handler) above this IF statement
  2. if cache handler isn't working (use the isWorking method) AND we're using MemcacheCacheHandler cache handler (you can do either instanceof on the object OR compare $handler_class), then use MemcachedCacheHandler

With CentOS, it's possible to install both PHP extensions (Memcache & Memcached) on any PHP version (even 5.x one). Therefore the assumption of fact, that if it's PHP 7, then the Memcache module is 100% non-available isn't true anymore.

This revision now requires changes to proceed.Jan 15 2021, 8:56 AM
alex added inline comments.Feb 22 2023, 4:02 AM
core/kernel/utility/cache.php
107–109 ↗(On Diff #886)

Instead of changing the fallback solution do this:

  1. delete this fallback code
  2. in the "\kInstallToolkit::getWorkingCacheHandlers" method change the $cache_handlers array as follows:
    • change 'Memcache' => 'Memcached', into 'Memcache' => 'Memcached (via "Memcache" extension)',
    • before the above-changed array element add 'Memcached' => 'Memcached (via "Memcached" extension)',
  3. update the test plan to include testing cache handler selection on an existing install via corresponding installation wizard step (no need to test re-install/upgrade for this)
alex added inline comments.Feb 22 2023, 4:07 AM
core/install/install_toolkit.php
974 ↗(On Diff #886)

Replace with

'Memcache' => 'Memcached (via "Memcache" extension)',

.

975 ↗(On Diff #886)

Replace with

'Memcache' => 'Memcached (via "Memcached" extension)',

.

erik edited the test plan for this revision. (Show Details)Feb 22 2023, 5:02 AM
erik updated this revision to Diff 1137.Feb 23 2023, 4:45 AM

Renoved fallback logic, updated test plan.

alex requested changes to this revision.Mar 17 2023, 5:43 AM
alex added inline comments.
core/kernel/utility/cache.php
106–111 ↗(On Diff #1137)

Please return this code.


When I said delete this fallback code in my previous comment that was meant only to selected code of that inline comment, which was:

if ( $handler_class == 'MemcacheCacheHandler' && PHP_VERSION_ID >= 70000 ) {
    $handler_class = 'MemcachedCacheHandler';
}
898 ↗(On Diff #1137)

Please remove.


No longer relevant.

914 ↗(On Diff #1137)

Please remove.


No longer relevant.

928 ↗(On Diff #1137)

Please remove the , 0.


According to Memcached server documentation this behavior is no longer supported.

This revision now requires changes to proceed.Mar 17 2023, 5:43 AM
alex retitled this revision from INP-1750 Support PHP Memcached extension for caching to INP-1750 - Support PHP Memcached extension for caching.Mar 17 2023, 11:45 AM
erik updated this revision to Diff 1140.Mar 20 2023, 6:28 AM
erik marked 4 inline comments as done.

Done requested changes - returned fallback to FakeCacheHandler zero time parameterusage and comments.

alex accepted this revision.Mar 21 2023, 3:50 AM
This revision is now accepted and ready to land.Mar 21 2023, 3:50 AM
This revision was landed with ongoing or failed builds.Mar 21 2023, 3:51 AM
This revision was automatically updated to reflect the committed changes.