Created
January 4, 2012 16:48
-
-
Save rpersaud/1560910 to your computer and use it in GitHub Desktop.
Figuring out memcache for mamp/php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@see http://www.re-cycledair.com/installing-memcache-on-mamp | |
Step 1: Install XCode | |
Step 2: Make the MAMP PHP binary files executable | |
sudo chmod +xrw /Applications/MAMP/bin/php5.3/bin/p* | |
Step 3: Get the Memcache extension source | |
cd ~ | |
wget http://pecl.php.net/get/memcache-2.2.5.tgz | |
tar -zxvf memcache-2.2.5.tgz | |
cd memcache-2.2.5 | |
Step 4: PHPize the Memcache extension files | |
/Applications/MAMP/bin/php5.3/bin/phpize | |
Step 5: Compile the Memcache extension | |
./configure | |
make | |
*If this configure doesnt work, and you're on a snow leopard arch, try this - | |
CFLAGS=-m32 CPPFLAGS=-m32 CCASFLAGS=-m32 ./configure | |
make | |
sudo make install | |
Step 6: Add the extension to the PHP.ini file | |
Add the following to the end of your PHP 5.3 ini file via the MAMP file menu. | |
extension=memcache.so | |
Step 7: Copy the memcache extension to the PHP extension folder | |
cp modules/memcache.so /Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-[yourtimestamp]/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$memcache = new Memcache; | |
$memcache->connect('localhost', 11211) or die ("Could not connect"); | |
$version = $memcache->getVersion(); | |
echo "Server's version: ".$version."<br/>\n"; | |
$tmp_object = new stdClass; | |
$tmp_object->str_attr = 'test'; | |
$tmp_object->int_attr = 123; | |
$memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server"); | |
echo "Store data in the cache (data will expire in 10 seconds)<br/>\n"; | |
$get_result = $memcache->get('key'); | |
echo "Data from the cache:<br/>\n"; | |
var_dump($get_result); | |
?> |
Got the php.net example to work by following this tutorial -
"One thing I experienced, re: start/stopping with MAMP. I found I was getting Connection Refused (61) errors in PHP, which were due to the memcached process not running at all.
I needed to make the following modifications to the startMemcached.sh script:
/usr/local/bin/memcached -m 24 -p 11211 -u user -d
- The full path needed to be added (alternately probably could do this with $PATH)
- Since MAMP was starting/stopping things as root, the -u user had to be added to tell it what user to impersonate (memcached won't run as root). Obviously "user" should be replaced with an actual user name..."
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a great tutorial on using memcache - http://www.search-this.com/2007/07/24/an-introduction-to-memcached/