1
+ <?php
2
+
3
+ define ("MEMC_SERVER_HOST " , "127.0.0.1 " );
4
+ define ("MEMC_SERVER_PORT " , 11211 );
5
+
6
+ function memc_get_instance ()
7
+ {
8
+ $ memcached = new Memcached ();
9
+ $ memcached ->addServer (MEMC_SERVER_HOST , MEMC_SERVER_PORT );
10
+ $ memcached ->flush ();
11
+ return $ memcached ;
12
+ }
13
+
14
+ function memc_run_test ($ test_function , $ options = array ())
15
+ {
16
+ foreach ($ options as $ option_set ) {
17
+ $ memc = memc_get_instance ();
18
+
19
+ foreach ($ option_set ['options ' ] as $ key => $ value ) {
20
+ if ($ memc ->setOption ($ key , $ value ) == false ) {
21
+ die ('Failed to set option: ' . $ key );
22
+ }
23
+ }
24
+ $ test_function ($ memc , $ option_set );
25
+ }
26
+ echo "TEST DONE " . PHP_EOL ;
27
+ }
28
+
29
+ function memc_create_combinations ($ name , $ serializer , $ ignore_object_type = false )
30
+ {
31
+ return array (
32
+ array (
33
+ 'title ' => "$ name serializer, ascii protocol " ,
34
+ 'options ' => array (
35
+ Memcached::OPT_SERIALIZER => $ serializer
36
+ ),
37
+ 'ignore_object_type ' => $ ignore_object_type
38
+ ),
39
+ array (
40
+ 'title ' => "$ name serializer, binary protocol " ,
41
+ 'options ' => array (
42
+ Memcached::OPT_BINARY_PROTOCOL => true ,
43
+ Memcached::OPT_SERIALIZER => $ serializer
44
+ ),
45
+ 'ignore_object_type ' => $ ignore_object_type
46
+ ),
47
+ );
48
+ }
49
+
50
+ function memc_get_serializer_options ()
51
+ {
52
+ $ options = memc_create_combinations ('PHP ' , Memcached::SERIALIZER_PHP );
53
+
54
+ if (defined ('Memcached::HAVE_IGBINARY ' )) {
55
+ $ options = array_merge ($ options , memc_create_combinations ('igbinary ' , Memcached::SERIALIZER_IGBINARY ));
56
+ }
57
+
58
+ if (defined ('Memcached::HAVE_JSON ' )) {
59
+ $ options = array_merge ($ options , memc_create_combinations ('JSON ' , Memcached::SERIALIZER_JSON , true ));
60
+ }
61
+ return $ options ;
62
+ }
0 commit comments