File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717// Include composer autoloader
1818require __DIR__ . '/../vendor/autoload.php ' ;
1919
20- $ InstanceCache = CacheManager::getInstance ('memcache ' );
20+ $ InstanceCache = CacheManager::getInstance ('memcache ' , ['servers ' => [
21+ [
22+ 'host ' =>'127.0.0.1 ' ,
23+ 'port ' => 11211 ,
24+ // 'sasl_user' => false, // optional
25+ // 'sasl_password' => false // optional
26+ ],
27+ ]]);
28+
2129/**
2230 * In case you need to enable compress_data option:
2331 * $InstanceCache = CacheManager::getInstance('memcache', ['compress_data' => true]);
Original file line number Diff line number Diff line change 1717// Include composer autoloader
1818require __DIR__ . '/../vendor/autoload.php ' ;
1919
20- $ InstanceCache = CacheManager::getInstance ('memcached ' );
20+ $ InstanceCache = CacheManager::getInstance ('memcached ' , ['servers ' => [
21+ [
22+ 'host ' =>'127.0.0.1 ' ,
23+ 'port ' => 11211 ,
24+ // 'sasl_user' => false, // optional
25+ // 'sasl_password' => false // optional
26+ ],
27+ ]]);
28+
2129/**
2230 * In case you need SASL authentication:
2331 * $InstanceCache = CacheManager::getInstance('memcache', ['sasl_user' => 'hackerman', 'sasl_password' => '12345']);
Original file line number Diff line number Diff line change 2727/**
2828 * Class Driver
2929 * @package phpFastCache\Drivers
30+ * @property MemcacheSoftware $instance
3031 */
3132class Driver implements ExtendedCacheItemPoolInterface
3233{
@@ -50,7 +51,6 @@ public function __construct(array $config = [])
5051 if (!$ this ->driverCheck ()) {
5152 throw new phpFastCacheDriverCheckException (sprintf (self ::DRIVER_CHECK_FAILURE , $ this ->getDriverName ()));
5253 } else {
53- $ this ->instance = new MemcacheSoftware ();
5454 $ this ->driverConnect ();
5555
5656 if (array_key_exists ('compress_data ' , $ config ) && $ config [ 'compress_data ' ] === true ) {
@@ -129,16 +129,21 @@ protected function driverClear()
129129 */
130130 protected function driverConnect ()
131131 {
132- $ servers = (!empty ($ this ->config [ 'memcache ' ]) && is_array ($ this ->config [ 'memcache ' ]) ? $ this ->config [ 'memcache ' ] : []);
132+ $ servers = (!empty ($ this ->config [ 'servers ' ]) && is_array ($ this ->config [ 'servers ' ]) ? $ this ->config [ 'servers ' ] : []);
133133 if (count ($ servers ) < 1 ) {
134134 $ servers = [
135- ['127.0.0.1 ' , 11211 ],
135+ [
136+ 'host ' =>'127.0.0.1 ' ,
137+ 'port ' => 11211 ,
138+ 'sasl_user ' => false ,
139+ 'sasl_password ' => false
140+ ],
136141 ];
137142 }
138143
139144 foreach ($ servers as $ server ) {
140145 try {
141- if (!$ this ->instance ->addserver ($ server [ 0 ], $ server [ 1 ])) {
146+ if (!$ this ->instance ->addServer ($ server [' host ' ], $ server [' port ' ])) {
142147 $ this ->fallback = true ;
143148 }
144149 if (!empty ($ server [ 'sasl_user ' ]) && !empty ($ server [ 'sasl_password ' ])){
Original file line number Diff line number Diff line change @@ -128,16 +128,21 @@ protected function driverClear()
128128 */
129129 protected function driverConnect ()
130130 {
131- $ servers = (!empty ($ this ->config [ 'memcache ' ]) && is_array ($ this ->config [ 'memcache ' ]) ? $ this ->config [ 'memcache ' ] : []);
131+ $ servers = (!empty ($ this ->config [ 'servers ' ]) && is_array ($ this ->config [ 'servers ' ]) ? $ this ->config [ 'servers ' ] : []);
132132 if (count ($ servers ) < 1 ) {
133133 $ servers = [
134- ['127.0.0.1 ' , 11211 ],
134+ [
135+ 'host ' =>'127.0.0.1 ' ,
136+ 'port ' => 11211 ,
137+ 'sasl_user ' => false ,
138+ 'sasl_password ' => false
139+ ],
135140 ];
136141 }
137142
138143 foreach ($ servers as $ server ) {
139144 try {
140- if (!$ this ->instance ->addServer ($ server [ 0 ], $ server [ 1 ])) {
145+ if (!$ this ->instance ->addServer ($ server [' host ' ], $ server [' port ' ])) {
141146 $ this ->fallback = true ;
142147 }
143148 if (!empty ($ server [ 'sasl_user ' ]) && !empty ($ server [ 'sasl_password ' ])){
You can’t perform that action at this time.
0 commit comments