memcache.php stats like apc.php
by Harun Yayli on Wednesday, May 21st, 2008 at 5:15 pm under Memcached, PHP, Programming
For a long time I was looking for a nice web interface like the apc.php (comes with the apc’s source) that displays whole nine yards of stats. The only good tool is memcache-tool from the danga guys. It’s quite complete but I guess I’m too lazy to go on the command line.
Anyways, I decided to rip write my own. Totally based on the original apc.php (I even recycled some functions) and apart from completeness, here is a memcache.php that you can get stats and dump from multiple memcache servers.
Here is a screenshot:

And here is the the source code.
As usual, this piece of software comes with the warnings:
- Don’t expect something complete, might have bugs and security problems etc.
- Do not install on a prod environment unless you’re sure!
- Feel free to add stuff to it, I’ll put it to google code or sf.net soon.
- Feel free to request features. (no I’m not planning a backup tool , there is memcache-tool for that)
- Enjoy!
Update: Small parse error is fixed
Recent Entries
- PHP Gurus in Montreal – I’m looking for 3 of them!
- Looking for 2 PHP Developers in Montreal (Senior and Intermediate)
- The difference between a bug and a feature
- Designing for Social Traction
- How to make Facebook shared links appear nice
- new pecl/memcache is out with memcache.php
- memcache.php flushes servers
- memcache.php can delete keys now
- memcache.php is now part of pecl/memcache
- memcache.php goes PECL
That’s very useful, thanks for publishing it.
By the way you have an extra comma (,) in the source code around line 486.
May 21st, 2008 at 10:47 pmHey Harun,
Just a small problem with the code – it throws an error while running. The comma on line 486 has to be a semi-colon. Changing that fixes the problem.
Cool Script btw !
May 22nd, 2008 at 2:28 amHave you talked to the pecl/memcache maintainers to get this script included into the package just like with pecl/apc?
May 22nd, 2008 at 2:59 amNice script!
There is a parse error on line 488, “menu_entry(2,’Variables’), ” should be “menu_entry(2,’Variables’);”
May 22nd, 2008 at 4:12 amHi, this is pretty cool, thanks for sharing!
May 22nd, 2008 at 8:37 amregards, dz
Do you know of anything like this for Postgres?
May 22nd, 2008 at 8:56 am@James McGlinn, @Vinu Thomas, @Jason,
May 22nd, 2008 at 9:57 amThanks for noticing, parse error should be fixed now.
@Lukas
May 22nd, 2008 at 10:00 amGood idea. I’ll contact them to contribute the code to the pecl/memcache.
@Glen
May 22nd, 2008 at 10:07 amHmm.. No I’m not a Postres user at all.
No chance for a txt/tarball download? Pasting a phps file is always so ugly
May 22nd, 2008 at 12:20 pm@Trophaeum
May 22nd, 2008 at 12:49 pmDone
What about a mysql version then?
May 22nd, 2008 at 2:41 pm@Glen
May 22nd, 2008 at 3:08 pmThere are way too many tools for mysql. Mysql Administrator is really great too (http://www.mysql.com/products/tools/administrator/). I don’t really have a good idea that is not covered by MysqlAdministrator.
Awesome script. Thanks so much.
July 25th, 2008 at 3:44 pmBTW, I made one small change to the codebase
I changed this line:
Header(“WWW-Authenticate: Basic realm=\”APC Login\”");
to this:
Header(“WWW-Authenticate: Basic realm=\”Memcache Login\”");
I actually have APC devices in my network and thought it was a little confusing. Anyway thanks so much. This is much easier to keep dibs on my memory servers than using the command line all the time.
July 25th, 2008 at 3:46 pmThanks,
I’ve added a flush cache link, fixed the ‘evicted’ text and made HTTP auth optional. Where do I send the patch?
July 30th, 2008 at 8:02 pm@michael.
Thank you. I’ve recently corrected those too.
August 2nd, 2008 at 4:31 pmYou can contact me by email. see the About page.
great script. perfect for keeping an eye on memcached!
August 9th, 2008 at 3:55 amThanks for this script. Very usefull to check all of our memcache servers…
August 25th, 2008 at 9:55 pmCould you please include this line into HTML code? Thanks.
September 15th, 2008 at 11:48 amHm… where did the code it go? Nvm. Here’s a pastebin link:
September 15th, 2008 at 11:51 amhttp://pastebin.ca/1203462
thank u r information
it very useful
October 21st, 2008 at 9:40 amHow do you use this? I uploaded it, went to the page and it asks for a username/password.
January 5th, 2009 at 5:39 pmWhat does “hits & misses” mean?
January 5th, 2009 at 10:59 pmim kind of a novice.. can anybody tell me how to installl it on my server?
January 27th, 2009 at 7:53 amShouldn’t the default screen Hit Rate reflect the total of all the memcached servers? If you have server1 with a hit rate of 50 requests per second and server2 with a hit rate of 100 requests per second, should the total be 150 requests per second instead of the average of 75 (which seems to be what your scritp is doing)?
January 27th, 2009 at 11:47 amMuch thanks for this script!
February 3rd, 2009 at 8:07 amcool! useful!
February 19th, 2009 at 9:43 pmthank’s !
Hello, Memcache running and hearing default port 11211, not a firewall issue also, but I’m receiving a Cant connect to:mymemcache-server1:11211
May 9th, 2009 at 8:35 pmGracias
Gustavo
Perfect! Thanks!
May 27th, 2009 at 6:46 amI have memcache running on localhost (Windows XP box) and provide Admin login and password, I still get
Rejected!
Wrong Username or Password!
I tried running memcached with -u – that didn’t help either…
June 19th, 2009 at 4:29 pmThanks A Lot For Sharing. Great Tool.
June 25th, 2009 at 12:41 amhi there… there is a bug about gziped values… they shown as binary chars…
July 16th, 2009 at 7:31 amThanks very much, this is just what I was looking for
September 11th, 2009 at 5:48 pmIt ould be nice to implement server display names.
For exaple, instead of:
$MEMCACHE_SERVERS[] = array(’server:port’)
How about
$MEMCACHE_SERVERS[] = array(’server:port’, ‘Nisplay Name’)
Also, it seems the pie chart doesn’t render correctly; I have six memcached instances running, and if the total use is, say, 2MB out of a total 256MB, the pie chart shows 99.9% usage (all orange) but the text stats are correct.
Otherwise, very nice, clean tool! Good job!
October 3rd, 2009 at 7:09 pmWoops, my last comment contained a typo. I meant this:
For exaple, instead of:
$MEMCACHE_SERVERS[] = ’server:port’
How about
October 3rd, 2009 at 7:14 pm$MEMCACHE_SERVERS[] = array(’server:port’, ‘Display Name’)
Thanks for the tool. It was just what I needed after a new memcached implementation.
January 7th, 2010 at 12:01 pmGreat tool, keep up the good work..
January 29th, 2010 at 3:15 pmAwesome! Just what I was looking for.
February 23rd, 2010 at 4:52 amMany Thanks!!
Can it also show the memcached version, just like the PHP version you already, it’s a nice debug fact
March 28th, 2010 at 7:55 amit is a good job!
April 13th, 2010 at 2:31 ami like this tool!
Adding multiple memcached instances as an array does not work. Neither
$MEMCACHE_SERVERS[] = array(
“localhost:11211″,
“localhost:11212″,
“localhost:11213″,
“localhost:11214″,
“localhost:11215″,
“localhost:11216″,
“localhost:11217″,
“localhost:11218″,
“localhost:11219″,
);
nor
$MEMCACHE_SERVERS[] = array(
‘localhost:11211′,
‘localhost:11212′,
‘localhost:11213′,
‘localhost:11214′,
‘localhost:11215′,
‘localhost:11216′,
‘localhost:11217′,
‘localhost:11218′,
‘localhost:11219′,
);
results i useful output. Message on memcache.php:
“Cant connect to:Array:”
May 24th, 2010 at 1:56 pmThanks, very helpful. I used a small function to make it work with unix sockets.
function gethostport($server) {
October 13th, 2010 at 5:55 amif(strpos($server, ‘unix:/’)===0){
$host = $server;
$port = 0;
}
else{
$strs = explode(‘:’,$server);
$host = $strs[0];
$port = $strs[1];
}
return array($host, $port);
}
Thanks for this! It was tough to find a memcached monitor.
October 21st, 2010 at 10:02 pmThanks for sharing, will implement it tonight – this memcache.php is exactly what I was looking for.
December 22nd, 2010 at 4:08 pmCheers Bertram
Awesome script – saves me a whoooooooole lot of leg work! Great job!
April 3rd, 2011 at 8:46 pmPublish code to github, it will be easy to stay tuned for updates also for forks…
August 16th, 2011 at 3:09 pmHello,
Thank you for this tool I’m using often. I have done some changes to improve readability of the slab dumb, but since comments are not allowed, I’ve posted them on my git server: http://git.osinet.eu/gitweb?p=tools/memcache_ui.gi
September 9th, 2011 at 8:28 amHello,
Thank you for this tool I’m using often. I have done some changes to improve readability of the slab dumb, but since comments are not allowed to have attachments, I’ve posted them on my git server: http://git.osinet.eu/gitweb?p=tools/memcache_ui.git
September 9th, 2011 at 8:29 amThank you very much.
@Redakteur: Great job, I use the the socket as well and it is working fine.
September 15th, 2011 at 8:40 amWwow, excellent tool!, thank you so much =D.
July 10th, 2012 at 8:53 pmI’m using it, and is very helpful, thanks =D
The best wishes for you =)