Cuối cùng tôi đã có memcache chạy trên máy tính ở nhà của tôi vì vậy tôi có thể bắt đầu phát triển với nó cuối cùng!Làm thế nào để bạn sử dụng memcache với PHP
Tôi không có một khởi đầu tốt mặc dù tôi đang cố gắng sử dụng các mã trên
php.net @ memcache-set Tôi không thể để có được một trong hai mã ví dụ để làm việc mà họ đăng
Tôi cố gắng này:
<?php
/* procedural API */
$memcache_obj = memcache_connect('memcache_host', 11211);
memcache_set($memcache_obj, 'var_key', 'some variable', 0, 30);
echo memcache_get($memcache_obj, 'var_key');
?>
Và sau đó
<?php
/* OO API */
$memcache_obj = new Memcache;
$memcache_obj->connect('memcache_host', 11211);
$memcache_obj->set('var_key', 'some really big variable', MEMCACHE_COMPRESSED, 50);
echo $memcache_obj->get('var_key');
?>
Và có những sai sót từ các mã trên;
Warning: Memcache::connect() [memcache.connect]: Can't connect to memcache_host:11211, A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060) in C:\webserver\htdocs\test\memcache\index.php on line 36
Warning: Memcache::set() [memcache.set]: Failed to extract 'connection' variable from object in C:\webserver\htdocs\test\memcache\index.php on line 42
Warning: Memcache::get() [memcache.get]: Failed to extract 'connection' variable from object in C:\webserver\htdocs\test\memcache\index.php on line 44
sau đó tôi tìm thấy mã này trên mạng ở đâu đó và nó làm việc
<?php
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");
$tmp_object = new stdClass;
$tmp_object->str_attr = 'test';
$tmp_object->int_attr = 123;
// add cache
$memcache->set('key', $tmp_object, false, 30) or die ("Failed to save data at the server");
echo "Store data in the cache (data will expire in 30 seconds)<br/>\n";
// get cache
$get_result = $memcache->get('key');
echo "Data from the cache:<br/>\n";
var_dump($get_result);
?>
Làm thế nào tôi có thể lấy ví dụ từ PHP. net để làm việc mặc dù?
Ngoài ra tôi rất thích nhìn thấy bất kỳ mã emample liên quan đến memcache bạn có thể muốn chia sẻ tôi sẽ thực sự đánh giá cao khi nhìn thấy một số ví dụ làm việc
Memcache có được thiết lập với số cổng mặc định (11211) và được đặt để nghe trên tất cả các giao diện không? – Kazar
đây là seting của tôi [Memcache] memcache.allow_failover = 1 memcache.max_failover_attempts = 20 memcache.chunk_size = 8192 memcache.default_port = 11211 – JasonDavis
đó là các thiết lập duy nhất mà tôi có kể từ khi tôi đang sử dụng một phiên bản windows – JasonDavis