PHP 8.2.30
Preview: 033.phpt Size: 3.88 KB
//opt/alt/tests/alt-php85-pecl-memcache_8.2-2.el8/tests/033.phpt

--TEST--
memcache->addServer() with server failure callback
--SKIPIF--
<?php include 'connect.inc'; if (!isset($host2)) die('skip $host2 not set'); ?>
--FILE--
<?php

include 'connect.inc';

function _callback_server_failure($host, $tcp_port, $udp_port, $error, $errnum) {
	var_dump($host);
	var_dump($tcp_port);
	var_dump($udp_port);
	var_dump($error);
	var_dump($errnum);

	global $memcache;
	$memcache->setServerParams($host, $tcp_port, 1, -1, false, '_callback_server_failure');
}

// Test function callback using addServer()
$memcache = new Memcache();
$memcache->addServer($nonExistingHost, $nonExistingPort, false, 1, 1, 15, true, '_callback_server_failure');

$result1 = $memcache->set('test_key', 'test-032-01');
var_dump($result1);

class MemcachedFailureHandler {
	function _callback_server_failure($host, $tcp_port, $udp_port, $error, $errnum) {
		var_dump($host);
		var_dump($tcp_port);
		var_dump($udp_port);
		var_dump($error);
		var_dump($errnum);
	}
}

// Test OO callback using setServerParams()
$memcache = new Memcache();
$memcache->addServer($nonExistingHost, $nonExistingPort, false);
$result2 = $memcache->setServerParams($nonExistingHost, $nonExistingPort, 1, 15, true, 
	array(new MemcachedFailureHandler(), '_callback_server_failure'));
var_dump($result2);

$result3 = $memcache->set('test_key', 'test-032-01');
var_dump($result3);

// Test giving non-existing callback to addServer()
$memcache = new Memcache();
$result4 = @$memcache->addServer($nonExistingHost, $nonExistingPort, false, 1, 1, 15, true, 'non_existing_user_function');
var_dump($result4);

// Test giving non-existing callback to setServerParams()
$memcache = new Memcache();
$memcache->addServer($nonExistingHost, $nonExistingPort, false);
$result5 = @$memcache->setServerParams($nonExistingHost, $nonExistingPort, 1, 15, true, 'non_existing_user_function');
var_dump($result5);

// Test self-referencing callback
class MyMemcache extends Memcache {
	function _callback_server_failure($host, $tcp_port, $udp_port, $error, $errnum) {
		var_dump($host);
	}
}
$memcache = new MyMemcache();
$memcache->addServer($nonExistingHost, $nonExistingPort, false);
$result6 = $memcache->setServerParams($nonExistingHost, $nonExistingPort, 1, 15, true, 
	array($memcache, '_callback_server_failure'));
$result7 = @$memcache->set('test_key', 'test-032-01');

var_dump($result6);
var_dump($result7);

// Test resetting callback to null
$memcache = new Memcache();
$memcache->addServer($nonExistingHost, $nonExistingPort, false, 1, 1, 15, true, '_callback_server_failure');
$result8 = $memcache->setServerParams($nonExistingHost, $nonExistingPort, 1, 15, true, null);
$result9 = @$memcache->set('test_key', 'test-032-01');

var_dump($result8);
var_dump($result9);

// Test MemcachePool::setFailureCallback()
function _callback_server_failure2($host, $tcp_port, $udp_port, $error, $errnum) {
	var_dump($error);
}

$memcache = new MemcachePool();
$memcache->addServer($nonExistingHost, $nonExistingPort);
$result8 = $memcache->setFailureCallback('_callback_server_failure2');
$result9 = @$memcache->set('test_key', 'test-032-01');

var_dump($result8);
var_dump($result9);

$result8 = $memcache->setFailureCallback(null);
$result9 = @$memcache->set('test_key', 'test-032-01');

var_dump($result8);
var_dump($result9);

// Test refcount
function test_connect() {
	global $mc, $nonExistingHost, $nonExistingPort;
	$mc = new Memcache();
	$mc->addServer($nonExistingHost, $nonExistingPort, false, 1, 1, 15, true, '_callback_server_failure2');
}

test_connect();
$result10 = $mc->set('test_key', 'test-032-02');
var_dump($result10);

?>
--EXPECTF--
string(%d) "%s"
int(%d)
int(%d)
string(%d) "Connection %s"
int(%d)
bool(false)
bool(true)
string(%d) "%s"
int(%d)
int(%d)
string(%d) "Connection %s"
int(%d)
bool(false)
bool(false)
bool(false)
string(%d) "%s"
bool(true)
bool(false)
bool(true)
bool(false)
string(%d) "%s"
bool(true)
bool(false)
bool(true)
bool(false)
string(%d) "Connection %s"
bool(false)

Directory Contents

Dirs: 0 × Files: 84

Name Size Perms Modified Actions
801 B lrw-r--r-- 2025-12-23 23:31:59
Edit Download
773 B lrw-r--r-- 2025-12-23 23:31:59
Edit Download
1.21 KB lrw-r--r-- 2025-12-23 23:31:59
Edit Download
1.14 KB lrw-r--r-- 2025-12-23 23:31:59
Edit Download
523 B lrw-r--r-- 2025-12-23 23:31:59
Edit Download
3.81 KB lrw-r--r-- 2025-12-23 23:31:59
Edit Download
430 B lrw-r--r-- 2025-12-23 23:31:59
Edit Download
453 B lrw-r--r-- 2025-12-23 23:31:59
Edit Download
302 B lrw-r--r-- 2025-12-23 23:31:59
Edit Download
548 B lrw-r--r-- 2025-12-23 23:31:59
Edit Download
613 B lrw-r--r-- 2025-12-23 23:31:59
Edit Download
554 B lrw-r--r-- 2025-12-23 23:31:59
Edit Download
499 B lrw-r--r-- 2025-12-23 23:31:59
Edit Download
325 B lrw-r--r-- 2025-12-23 23:31:59
Edit Download
396 B lrw-r--r-- 2025-12-23 23:31:59
Edit Download
437 B lrw-r--r-- 2025-12-23 23:31:59
Edit Download
276 B lrw-r--r-- 2025-12-23 23:31:59
Edit Download
394 B lrw-r--r-- 2025-12-23 23:31:59
Edit Download
398 B lrw-r--r-- 2025-12-23 23:31:59
Edit Download
1.62 KB lrw-r--r-- 2025-12-23 23:31:59
Edit Download
852 B lrw-r--r-- 2025-12-23 23:31:59
Edit Download
898 B lrw-r--r-- 2025-12-23 23:31:59
Edit Download
1.29 KB lrw-r--r-- 2025-12-23 23:31:59
Edit Download
1.01 KB lrw-r--r-- 2025-12-23 23:31:59
Edit Download
1.03 KB lrw-r--r-- 2025-12-23 23:31:59
Edit Download
1.30 KB lrw-r--r-- 2025-12-23 23:31:59
Edit Download
1.32 KB lrw-r--r-- 2025-12-23 23:31:59
Edit Download
1.72 KB lrw-r--r-- 2025-12-23 23:31:59
Edit Download
904 B lrw-r--r-- 2025-12-23 23:31:59
Edit Download
1.31 KB lrw-r--r-- 2025-12-23 23:31:59
Edit Download
1.33 KB lrw-r--r-- 2025-12-23 23:32:00
Edit Download
1.23 KB lrw-r--r-- 2025-12-23 23:32:00
Edit Download
677 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
882 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
2.00 KB lrw-r--r-- 2025-12-23 23:32:00
Edit Download
2.03 KB lrw-r--r-- 2025-12-23 23:32:00
Edit Download
358 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
1.32 KB lrw-r--r-- 2025-12-23 23:32:00
Edit Download
557 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
2.26 KB lrw-r--r-- 2025-12-23 23:32:00
Edit Download
2.01 KB lrw-r--r-- 2025-12-23 23:32:00
Edit Download
3.88 KB lrw-r--r-- 2025-12-23 23:32:00
Edit Download
1.63 KB lrw-r--r-- 2025-12-23 23:32:00
Edit Download
775 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
1.50 KB lrw-r--r-- 2025-12-23 23:32:00
Edit Download
1.46 KB lrw-r--r-- 2025-12-23 23:32:00
Edit Download
486 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
851 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
790 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
1.00 KB lrw-r--r-- 2025-12-23 23:32:00
Edit Download
1.12 KB lrw-r--r-- 2025-12-23 23:32:00
Edit Download
1.68 KB lrw-r--r-- 2025-12-23 23:32:00
Edit Download
1.80 KB lrw-r--r-- 2025-12-23 23:32:00
Edit Download
868 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
1.64 KB lrw-r--r-- 2025-12-23 23:32:00
Edit Download
1.36 KB lrw-r--r-- 2025-12-23 23:32:00
Edit Download
728 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
709 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
706 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
590 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
611 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
988 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
573 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
769 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
1.56 KB lrw-r--r-- 2025-12-23 23:32:00
Edit Download
1.17 KB lrw-r--r-- 2025-12-23 23:32:00
Edit Download
213 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
954 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
1.20 KB lrw-r--r-- 2025-12-23 23:32:00
Edit Download
1.23 KB lrw-r--r-- 2025-12-23 23:32:00
Edit Download
1.29 KB lrw-r--r-- 2025-12-23 23:32:00
Edit Download
1.09 KB lrw-r--r-- 2025-12-23 23:32:00
Edit Download
2.35 KB lrw-r--r-- 2025-12-23 23:32:00
Edit Download
465 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
545 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
255 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
490 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
361 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
342 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
667 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
353 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
704 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
821 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download
429 B lrw-r--r-- 2025-12-23 23:32:00
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).