WebFaction
Community site: login faq

Hello,

This question was asked 1 on 1 with the Webfaction support team and we're still looking to solve the error but in the meantime I'll post this as a tutorial in case anyone has questions or can provide some insight.

So below are the steps I have taken to get where I am and everything works fine, the problem lies when I try to retrieve a Memcached key from memory that does not exist

In other words,

$mc = new Memcached(); $mc->addServer('localhost', <port>);

$mc->get("cat");

throw a 500 – Internal Server Error and in my logs I have

[Wed Jan 30 19:03:39 2013] [error] [client 209.29.54.55] Premature end of script headers: php53.cgi

It works if I $mc->set("cat", "meow") first, but not if I try to retrieve a non-existent key

This only happens with memcached as I tested it with file-based caching and doesn't have this problem

I am continuing to talk to the webfaction support team about it but in the meantime you can use the tutorial below so you don't bother them like I did :P


First to get memcached running on your box read here http://docs.webfaction.com/software/memcached.html#memcached

Now I specifically wanted memcached rather than memcache because that's what my Codeigniter supports nicely and documentation can be found here http://ellislab.com/codeigniter/user-guide/libraries/caching.html

Now on my Webfaction app I'm running Static/CGI/PHP-5.3 but anytime below you see php53 you can just replace it to php54 if you're running PHP-5.4

Install Memcached

Memcached is not installed by default for php, only memcache. If you want to use memcached instead, you will need to install into your account. Here are the commands:

mkdir ~/src ~/tmp

export TEMP=~/tmp

cd ~/src

wget https://launchpad.net/libmemcached/1.0/1.0.15/+download/libmemcached-1.0.15.tar.gz

tar zxf libmemcached-1.0.15.tar.gz

cd libmemcached-1.0.15

./configure --prefix=$HOME

make

make install

export TMPDIR=$HOME/tmp

export PATH="$HOME/bin:$PATH"

export C_INCLUDE_PATH="$HOME/include:$C_INCLUDE_PATH"

export LIBRARY_PATH="$HOME/lib:$LIBRARY_PATH"

export LD_LIBRARY_PATH="$HOME/lib:$LD_LIBRARY_PATH"

mkdir ~/pecl_install

cd ~/pecl_install

wget http://pecl.php.net/get/memcached-2.1.0.tgz

tar xzvf memcached-2.1.0.tgz

cd memcached-2.1.0

phpize53

./configure --with-php-config=/usr/local/bin/php53-config

make

mkdir ~/php53-exts

cp modules/memcached.so ~/php53-exts/

echo "extension_dir = $HOME/php53-exts" >> ~/webapps/yourapp/php.ini

echo "extension = memcached.so" >> ~/webapps/yourapp/php.ini

I ran into several problems with this but the webfaction support was happy to help

After some investigation the memcached pecl does not support socket connections. This means that you will need to use a port for the memcached connection instead of the sock method mentioned in the docs. Here are the steps to fix:

  1. Create a "Custom app (listening on port)" in the control panel: http://docs.webfaction.com/software/custom.html?highlight=custom#creating-a-custom-application

  2. Stop you other memcache process, first find the process by listing your process: ps -u $USER -o pcpu,rss,pid,command

Then use the kill command to stop the PID: kill <pid>

  1. Start memcached using the port from step 1: memcached -d -m 50 -p <port> -l 127.0.0.1

asked 31 Jan '13, 08:18

mcmaxx
11147
accept rate: 0%

edited 02 Feb '13, 21:56

ryans ♦♦
5.0k93160

Thanks for sharing your procedure!

(31 Jan '13, 12:29) seanf

since your examples use PHP 5.3, i've updated your code to use phpize53 instead of phpize54

(02 Feb '13, 21:19) ryans ♦♦

Still no luck

I tried this with 5.4 instead of 5.3 and with the newest version of libmemcached (the example above is one version behind) and still no luck

I've also tried this on a new account and environment, no luck

I've posted it on stackoverflow maybe they have some ideas

http://stackoverflow.com/questions/14668768/php-memcached-requesting-empty-key-throws-500-server-error

permanent link

answered 02 Feb '13, 20:07

mcmaxx
11147
accept rate: 0%

So here is the final solution to the problem in case anyone is interested in the future

Specifically, what's happening is that you built memcached against libmemcached 1.0.15, but our server already has an older version of libmemcached installed, version 0.31. The newer version of libmemcached is necessary; memcached 2.1.0 will not build against the older libmemcached. But when your PHP actually runs, it's trying to link against the shared libmemcached instead of the one you installed into ~/lib I'm going to attempt to rebuild memcached but statically-link it against libmemcached 1.0.15, to see if that helps.

Okay, it is possible to rebuild the PHP memcached PECL module statically against libmemcached, but then it also requires building memcached itself against the same libmemcached as well. Then, you have to ensure that your PHP calls the appropriate ~/bin/memcached when you do "new Memcached()" in the PHP code.

This is a bit too much work, so I'm looking into having the versions of memcached and libmemcached upgraded on all of our servers. A newer memcached + libmemcached would allow a new version of the memcached PHP PECL module to be installed without needing a local installation of libmemcached and static-linking for the binary.

permanent link

answered 03 Feb '13, 09:13

mcmaxx
11147
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×34
×31
×9
×8

question asked: 31 Jan '13, 08:18

question was seen: 5,678 times

last updated: 03 Feb '13, 09:13

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM