I want to start using memcache with PHP (on Ubuntu 9.10). There are lots of info online which appear to show how to do this. Suprisingly though, none of the articles (I have seen so far), explicitly state whether you need to RUN the memcache process BEFORE attempting to use it or whether by simply calling new MemCache() via the PHP client library, a process will be spawned (if not already running).
From the various docs I have read on this so far, these are the steps that I think make sense:
Number 3 is the part that I need confirmation on, because none of the docs I have seen so far mentions the lifespan of the memcache process.
Can someone experienced in this confirm if this is the correct steps? Also if I have missed a step, let me know.
As an aside, since I am relatively new to Linux, I would be grateful if someone could post an example of an init script that would be needed to run the memcache daemon process (assuming that the steps I have outlined above are correct)
memcached and Apache+PHP are two totally unrelated things, at first. The only thing is PHP is connecting to the memcached daemon.
So, yes, memcached (note the 'd
' at the end) must be started before you try using it : it you try connecting to a memcached server when it's not running, you just won't be able to connect -- it won't spawn a new daemon nor anything.
Using a simple comparison : it your Apache server is not started and you try to access to it using your browser, you'll get a "cannot connect" error ; it's exactly the same with PHP trying to connect to memcached : it will not be able to.
Now, for the installation process, here are a couple of notes, for the parts that don't look OK in what you said :
apt-get install memcached
or aptitude install memcached
memcache
extension for PHP -- so PHP has functions to connect to memcached.
php5-memcache
package of your distributionpecl install memcache
command, which will download the sources from pecl.php.net and compile them -- which means you'll need everything that's needed to compile software.
Edit : easier to answer here than in a comment
I said installing memcached should be OK -- on Ubuntu, it seems there is a trap :
Using this :
ps -Alf | grep memcached
I don't see any running daemon.
And when I try to start the daemon, I get the following:
$ sudo /etc/init.d/memcached start
Starting memcached: memcached disabled in /etc/default/memcached.
So, on Ubuntu, you have to edit /etc/default/memcached
, and change it ; instead of this :
# Set this to yes to enable memcached.
ENABLE_MEMCACHED=no
It should contain that :
# Set this to yes to enable memcached.
ENABLE_MEMCACHED=yes
Then, starting memcached should be possible :
$ sudo /etc/init.d/memcached start
Starting memcached: memcached.
test@tests: ~/temp
$ ps -Alf | grep mem
4 S nobody 3813 1 0 80 0 - 30025 ep_pol 00:17 pts/4 00:00:00 /usr/bin/memcached -m 64 -p 11211 -u nobody -l 127.0.0.1
0 R test 3819 2690 0 80 0 - 1834 - 00:17 pts/4 00:00:00 grep --color=auto mem
Note : now that memcached is enabled, it should be started automatically with your system, each time you reboot it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With