mirror of
https://github.com/php-win-ext/pecl-memcache.git
synced 2026-03-24 00:52:07 +01:00
Test and fix memcache session redundancy php8 (#87)
* Use zend_bool for ini bool settings I think that these might have uninitialized bytes when a data type larger than zend_bool is used for the ini setting, if the module globals are set from malloc? (Not 100% sure if the entire structure isn't set to 0 before being used) Related to #56 * add a redundancy test file add a redundancy test file checking multiple memcached restarts install pcntl in docker container so tests are running add also a Vagrantfile for easier dev env setup * fix the redundancy failover by having dataresult as null initially instead of empty string Co-authored-by: Tyson Andre <tysonandre775@hotmail.com> Co-authored-by: Tomas Srnka <tomassrnka@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
e014963c13
commit
c615b13d2f
@@ -1,10 +1,13 @@
|
||||
ARG PHP_IMAGE=php:8.0
|
||||
FROM $PHP_IMAGE
|
||||
|
||||
RUN docker-php-ext-configure pcntl --enable-pcntl \
|
||||
&& docker-php-ext-install -j$(nproc) pcntl
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
git \
|
||||
zlib1g-dev \
|
||||
memcached ;
|
||||
memcached ;
|
||||
|
||||
COPY docker/host.conf /etc/host.conf
|
||||
|
||||
|
||||
17
Vagrantfile
vendored
Normal file
17
Vagrantfile
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
VAGRANTFILE_API_VERSION = '2'
|
||||
|
||||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
config.vm.box = 'ubuntu/bionic64'
|
||||
|
||||
config.vm.provider :virtualbox do |vb|
|
||||
vb.name = 'ext-memcache-dev'
|
||||
vb.memory = 1024
|
||||
vb.cpus = 2
|
||||
end
|
||||
|
||||
config.vm.provision 'docker'
|
||||
|
||||
end
|
||||
@@ -319,7 +319,7 @@ PS_READ_FUNC(memcache)
|
||||
ZVAL_NULL(&addresult);
|
||||
|
||||
/* third request fetches the data, data is only valid if either of the lock requests succeeded */
|
||||
ZVAL_EMPTY_STRING(&dataresult);
|
||||
ZVAL_NULL(&dataresult);
|
||||
|
||||
/* create requests */
|
||||
if (php_mmc_session_read_request(pool, &zkey, lockparam, &addresult, dataparam, &lockrequest, &addrequest, &datarequest) != MMC_OK) {
|
||||
|
||||
75
tests/redundancy_test.phpt
Normal file
75
tests/redundancy_test.phpt
Normal file
@@ -0,0 +1,75 @@
|
||||
--TEST--
|
||||
redundancy test
|
||||
--SKIPIF--
|
||||
<?php include 'connect.inc'; if (!MEMCACHE_HAVE_SESSION) print 'skip not compiled with session support'; else if (!function_exists('pcntl_fork')) print 'skip not compiled with pcntl_fork() support'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
include 'connect.inc';
|
||||
|
||||
$sid = md5(rand());
|
||||
|
||||
ini_set('session.save_handler', 'memcache');
|
||||
ini_set('memcache.session_save_path', "tcp://$host:$port,tcp://$host2:$port2");
|
||||
ini_set('memcache.session_redundancy', 3);
|
||||
|
||||
$memcache1 = test_connect1();
|
||||
$memcache2 = test_connect2();
|
||||
|
||||
$pid = pcntl_fork();
|
||||
if (!$pid) {
|
||||
// In child process
|
||||
session_id($sid);
|
||||
session_start();
|
||||
if (!isset($_SESSION['counter']))
|
||||
$_SESSION['counter'] = 0;
|
||||
$_SESSION['counter'] += 1;
|
||||
session_write_close();
|
||||
|
||||
exit(0);
|
||||
}
|
||||
pcntl_waitpid($pid, $status);
|
||||
|
||||
$memcache1->flush();
|
||||
|
||||
$pid = pcntl_fork();
|
||||
if (!$pid) {
|
||||
// In child process
|
||||
session_id($sid);
|
||||
session_start();
|
||||
if (!isset($_SESSION['counter']))
|
||||
$_SESSION['counter'] = 0;
|
||||
$_SESSION['counter'] += 1;
|
||||
session_write_close();
|
||||
|
||||
exit(0);
|
||||
}
|
||||
pcntl_waitpid($pid, $status);
|
||||
|
||||
$memcache2->flush();
|
||||
|
||||
$pid = pcntl_fork();
|
||||
if (!$pid) {
|
||||
// In child process
|
||||
session_id($sid);
|
||||
session_start();
|
||||
if (!isset($_SESSION['counter']))
|
||||
$_SESSION['counter'] = 0;
|
||||
$_SESSION['counter'] += 1;
|
||||
session_write_close();
|
||||
|
||||
exit(0);
|
||||
}
|
||||
pcntl_waitpid($pid, $status);
|
||||
|
||||
|
||||
session_id($sid);
|
||||
session_start();
|
||||
var_dump($_SESSION);
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
array(1) {
|
||||
["counter"]=>
|
||||
int(3)
|
||||
}
|
||||
Reference in New Issue
Block a user