1

Memcached should be installed correctly. I'm using php 5.4

memcached settings

With this code I should get '99' as a result but I end up with 'bool(false)'.

  $m = new Memcached();
  $m->addServer('localhost', 11211);

  $m->set('int', 99);

  var_dump($m->get('int'));
Shredsauce
  • 63
  • 1
  • 9
  • Save the value of `$m->set('int', 99);` to a variable, then `var_dump` that variable. What is its value? – Nate Dec 11 '15 at 17:16
  • Are you sure you have up and running `memcached` on your localhost? I've just tried the code on a machine without running `memcached` and got the same result so that would be my guess. – mrun Dec 11 '15 at 17:16
  • And can you do the same thing for the `addServer()` function? – Nate Dec 11 '15 at 17:18
  • @NateB I still get bool(false) when I do that. With the addServer() function I get bool(true) though – Shredsauce Dec 11 '15 at 17:39
  • What happens if you change `addServer` to `connect` ? – Nate Dec 11 '15 at 17:46
  • @NateB I get "Fatal error: Call to undefined method Memcached::connect()" – Shredsauce Dec 11 '15 at 17:54
  • Ok well scratch that idea :) What about replacing `set` with `add`? – Nate Dec 11 '15 at 18:00
  • @NateB nope, still get bool(false). I'm checking to make sure Memcached is actually installed. I used class_exists('Memcached') and it came out as true so I'm pretty sure it should be installed. – Shredsauce Dec 11 '15 at 18:07
  • If the `addServer()` method returns `true`, as you claim, than it's definitely installed. I'm at a loss now though, I'm sorry. Hopefully someone else can step in to help – Nate Dec 11 '15 at 18:08
  • 1
    @Shredsauce you don't need only the PHP `memcached` extension. You need to install the actual `memcached` server as well. If you're on Ubuntu you could try doing so by `sudo apt-get install memcached` – mrun Dec 11 '15 at 18:10
  • @mrun I did that and it gives me "memcached is already the newest version" – Shredsauce Dec 11 '15 at 18:18
  • @Shredsauce so is it working actually? What does `ps ax | grep memcached` give you? And probably try starting it with `sudo service memcached start`? – mrun Dec 11 '15 at 18:22
  • `ps ax | grep memcached` gives me "13699 pts/399 S+ 0:00 grep --color=auto memcached" – Shredsauce Dec 11 '15 at 18:23
  • hmm, `sudo service memcached start` gives me "Starting memcached: memcached disabled in /etc/default/memcached" – Shredsauce Dec 11 '15 at 18:24
  • @Shredsauce So, there you go. You should enable it in `/etc/default/memcached` by making `ENABLE_MEMCACHED=yes`. – mrun Dec 11 '15 at 18:26
  • I set `/etc/default/memcached` to `ENABLE_MEMCACHED=yes` and then did `sudo /etc/init.d/memcached start` but I'm still getting 'bool(false)' when I should be getting '99' – Shredsauce Dec 11 '15 at 18:35
  • I'm trying different versions of php to see if that's the issue. – Shredsauce Dec 11 '15 at 18:41
  • @Shredsauce So can you confirm `memcached` is working? Try `telnet localhost 11211` and then trying to set a key data by following [these](http://blog.elijaa.org/?post/2010/05/21/Memcached-telnet-command-summary) guidelines – mrun Dec 11 '15 at 18:54
  • I get "Trying 127.0.0.1... telnet: Unable to connect to remote host: Connection refused" when I do `telnet localhost 11211` – Shredsauce Dec 11 '15 at 19:11
  • @Shredsauce OK, so once again `ps ax | grep memcached` please. Is it working? Do you get any errors while trying to start it? – mrun Dec 11 '15 at 19:13
  • No errors, just "4322 pts/399 S+ 0:00 grep --color=auto memcached" – Shredsauce Dec 11 '15 at 19:16
  • Well, clearly your `memcached` is not running. Check out your log files. – mrun Dec 11 '15 at 19:33
  • So, any luck with the `memcached`? – mrun Dec 11 '15 at 21:43
  • Nope, I couldn't get it working unfortunately. Dreamhost doesn't officially support it but I'll call them anyways and see if they can help me out. Thanks for your help – Shredsauce Dec 12 '15 at 22:42
  • @mrun I tried it out again today and got it working. I'm not 100% sure what I did to get it working but it works. – Shredsauce Jan 06 '16 at 21:15
  • @MalcolmArcand well I guess you've got `memcached` up and running but the important thing is that you've got everything working now :-) I'm glad to hear that! – mrun Jan 06 '16 at 21:30

1 Answers1

1

This has been asked long ago, yet ranks up at Google search so the answer might be helpful for someone looking for the answer to this question.

Check if Memcached is really installed

Run the command telnet 127.0.0.1 11211 and if the connection fails then you need to install Memcached or check if your Firewall allows the port 11211 connections.

For Ubuntu, the command is sudo apt-get install memcached

Anand Singh
  • 1,091
  • 13
  • 21