SocialEngine 4: Speedup using Memcached / APC /Xcache

Andrew - SocialEngine

The current SocialEngine platform has always been very slowly even when there are not many users online.

There are many ways to try and speed up the site by using the APC, compressing the HTML, js, and CSS but this doesn’t always help improve the performance.

This Blog and its instructions are for Users that have their own Decided Servers, with a good understanding of the servers coding

Caching is the vital part of any website and helps a website to respond quickly. Social engine allows a variety of caching solutions like file based, memcache, APC (Alternative Php cache) and Xcache for the platform. Using one of the caching solutions would speed up the performance of socialengine 4. If you don’t have configured the memcached or APC or Xcache then you can use file system based caching but its much slower than the other caching solutions. We would recommend using one of the caching solutions to speed up the socialengine. In this article, we should show the instructions to install and configure caching for socialengine. We assume that the socialengine is running in the production mode.

Memcache is a distributed caching which can be used in a scenario where an application is running on several web servers. All the data stored in memcached would be distributed across all webservers. Since it requires dealing with network protocols in order to support the distributed part of caching, it is slower compared to APC/XCache cache in case of application is running on single server. While using APC/Xcache on distributed system would require manual copy of data on all the servers. APC/XCache are non distributed cache and data can be stored on the local web-server only. APC/XCache op-code caching saves on the compile and execution times of PHP thus loading of the socialengine become faster. Some people got confused whether Memcached can be used with the APC/Xcache (opcode). We can use the combination of MEMcached (as data storage) and APC/Xcache (as opcode for php).

Now we are going to show the installation and configuration of Memcached, APC and Xcache for socialengine on Centos.

Install and Configure Memcached with SocialEngine

1) Install memcached

tar zxpfv memcached*
cd memcached-1.4.5
make install
./memcached -u memcached -d -m 64 -l -p 11211

2) Install PHP Extension.

Download and install latest stable memcache version from PECL.

tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5
make install will be install in php modules directory, now enable extension in php.ini

To find out your php.ini location, execute following command

php -i | grep php.ini
Configuration File (php.ini) Path = /usr/local/lib
Loaded Configuration File = /usr/local/lib/php.ini
vi /usr/local/lib/php.ini
extension = “”

save the file and restart httpd server

/etc init.d/httpd restart

To check is memcache extension loaded inphp, execute following command.

php -i | grep memcache
memcache support = enabled

3) Configure memcached in socialengine

Go to http://yourserver/index.php/admin/core/settings/performance

2. Enable caching with memcached and add parameters specific to memcached.

3. Save the changes

Install and Configure APC with SocialEngine

By default there can be one opcode caching for php so if there is already any opcode (eaccelerator etc.) then disable that to allow APC to act as opcode.

1) Install APC

yum install php-pear
yum install php-devel
yum install httpd-devel
yum install pcre-devel
pecl install apc
echo ""  /etc/php.d/apc.ini
/etc/init.d/httpd restart

To check is APC extension loaded in php, execute following command.

php phpinfo()

2) Configure APC in socialengine

1. Go to http://yourserver/index.php/admin/core/settings/performance

2. Enable caching with APC option.

3. Save the changes

Install and Configure Xcache with SocialEngine

1) Install Xcache

tar -zxvf xcache-1.3.1.tar.gz
cd xcache-1.3.1
./configure --enable-xcache
make install

You would need to change timelib_structs.h to install Xcache

Find line:

  1. #include

Replace / update as follows:

  1. #include “timelib_config.h”

Create one password for Xcache administration:

# echo -n “yourpassword”| md5sum

Then open php.ini, and add the following append configuration directives.

zend_extension      = /usr/lib/php/modules/
xcache.admin.user   = "admin"
;how to create md5 pwd: echo -n "password"| md5sum
xcache.admin.pass   = "a364b1d54799c713b8a377de50f8ed3c"
; Change xcache.size to tune the size of the opcode cache
; to disable: xcache.size=0
; to enable : xcache.size=64M etc (any size > 0) and your system mmap allows
; someone said, if =64 will get problem
xcache.size         = 32M
xcache.shm_scheme   = "mmap"
; set to cpu count (cat /proc/cpuinfo |grep -c processor)
xcache.count        = 4
; just a hash hints, you can always store count(items) slots
xcache.slots        = 8K
; ttl of the cache item, 0=forever
xcache.ttl          = 0
; interval of gc scanning expired items, 0=no scan, other values is in seconds
xcache.gc_interval  = 0
; Change xcache.var_size to adjust the size of variable cache
; same as aboves but for variable cache, if you have not used xcache function in script,forget it
xcache.var_size     = 8M
xcache.var_count    = 1
xcache.var_slots    = 8K
xcache.var_ttl      = 0
xcache.var_maxttl   = 0
xcache.var_gc_interval =     300
xcache.test         = Off
xcache.readonly_protection = On
; for *nix, xcache.mmap_path is a file path, not directory.
; Use something like "/tmp/xcache" if you want to turn on ReadonlyProtection
; 2 group of php won’t share the same /tmp/xcache
; for win32, xcache.mmap_path=anonymous map name, not file path
xcache.mmap_path    = "/tmp/xcache"
; leave it blank(disabled) or "/tmp/phpcore/"
; make sure it’s writable by php (without checking open_basedir)
xcache.coredump_directory =   ""
; per request settings
xcache.cacher       = On
xcache.stat         = On
xcache.optimizer    = Off
; per request settings
; enable coverage data collecting for xcache.coveragedump_directory and
; xcache_coverager_start/stop/get/clean() functions (will hurt executing performance)
xcache.coverager    = On
; ini only settings
; make sure it’s readable (care open_basedir) by coverage viewer script
; requires xcache.coverager=On
xcache.coveragedump_directory = ""

2) Configure Xcache in SocialEngine

1. Go to http://yourserver/index.php/admin/core/settings/performance

2. Enable caching with Xcache option and add user’s credentials.

3. Save the changes


We found Xcache little faster than the Memcached/APC for SocialEngine

Please feel free to comments or suggest other technique of caching.

It is possible to do performance tuning by yourself, or getting developers to do this. However, in our experience, the community owners are really more focused on making their community an engaging experience via functionality or graphics. Similarly, most developers can write PHP code, but very few have the experience of various tools for improving performance.

Custom optimization may be required when your community grows..



Looking for quality SocialEngine Hosting? Look no further than Arvixe Web Hosting

Tags: , , , , , , | Posted under SocialEngine | RSS 2.0

Author Spotlight

Andrew Cross

Hi, I'm Andrew. A am a 26, ICT Administrator which offers support to company's around the South Wales Area. I have created a few social sites for myself and other company's. So far 2 out of 3 have been successful using the powerful SocialEngine Script. I continue to try and help the community of SocialEngine by giving Support and Technical Help where possible.

Leave a Reply

Your email address will not be published. Required fields are marked *