Store
Community Documentation

v3 Knowledgebase

Tips on Improving Performance of phpFox:: Part 1

Being a SysAdmin , I'm always researching for ways to make my systems FASTER!
I just love speed, and so it's no surprise that I've been digging into the phpfox code to see what can be done to stretch phpfox's performance without breaking things up. Let's get started.
1. Hosting *most* of the static files on different server for load balancing.
I had posted a feature request here asking the phpfox development team to implement a feature to host static files on CDN or on a different server for load balancing purposes (see tracker : http://www.phpfox.com/tracker/view/8615/ ). Actually , for those who've been curious enough, you may have discovered that this was possible to accomplish without even doing editing the core files , assuming editing
/include/setting/common.sett.php
doesn't count as touching the core files.
Here's how to do this :
Let's call the secondary server used for load-balancing purposes ServerB and the main server where phpFox is install serverA.
1. Copy the following folders from serverA to serverB :

modules , include , theme ,static

You don't need to make any modifications on any files. just copy them as they are.

2. Edit this file
/include/setting/common.sett.php
on serverA .
What we are doing here is to configure ServerB to be used for serving static content (css, js ) . We shall modify the following entries :

$_CONF['core.url_static2'] = $_CONF['core.path'] . 'static/';
$_CONF['core.url_static'] = $cdnRootUrl . '/static/';


For simplicity sake , Use the following common.sett.php and change the line below to reflect serverB

$cdnRootUrl = 'http://ServerB.com/' ;


Here's how it should look like after editing.

PHP:
<?php
/**
 * [PHPFOX_HEADER]
 * 
 * @copyright           [PHPFOX_COPYRIGHT]
 * @author                      Raymond Benc
 * @package             Phpfox
 * @version             $Id: common.sett.php 2880 2011-08-23 10:31:43Z Miguel_Espinoza $
 */

defined('PHPFOX') or exit('NO DICE!');

$_CONF['core.http'] = 'https://';
$_CONF['core.https'] = 'http://';



//Server to host static content
$cdnRootUrl 'http://ServerB.com/' ;


$_CONF['core.path'] = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' 'https' 'http') . '://' $_CONF['core.host'] . $_CONF['core.folder'];
$_CONF['core.spath'] = $_CONF['core.path'] ;


$_CONF['core.dir_file'] = PHPFOX_DIR 'file' PHPFOX_DS;

$_CONF['core.url_file'] = $_CONF['core.path'] . 'file/';
$_CONF['core.url_file2'] = $cdnRootUrl '/file/' ;

$_CONF['core.dir_cache'] = $_CONF['core.dir_file'] . 'cache' PHPFOX_DS;
$_CONF['core.url_module'] = $_CONF['core.path'] . 'module/';

/* /file/ directories */
$_CONF['core.dir_pic'] = $_CONF['core.dir_file'] . 'pic' PHPFOX_DS;
$_CONF['core.url_pic'] = $_CONF['core.url_file'] . 'pic/';


$_CONF['core.dir_attachment'] = $_CONF['core.dir_file'] . 'attachment' PHPFOX_DS;
$_CONF['core.url_attachment'] = $_CONF['core.url_file'] . 'attachment/';

$_CONF['core.dir_emoticon'] = $_CONF['core.dir_pic'] . 'emoticon' PHPFOX_DS;
$_CONF['core.url_emoticon'] = $_CONF['core.url_pic'] . 'emoticon/';

$_CONF['core.dir_user'] = $_CONF['core.dir_pic'] . 'user' PHPFOX_DS;
$_CONF['core.url_user'] = $_CONF['core.url_pic'] . 'user/';


$_CONF['photo.dir_photo'] = $_CONF['core.dir_pic'] . 'photo' PHPFOX_DS;
$_CONF['photo.url_photo'] = $_CONF['core.url_pic'] . 'photo/';


$_CONF['poll.dir_image'] = $_CONF['core.dir_pic'] . 'poll' PHPFOX_DS;
$_CONF['poll.url_image'] = $_CONF['core.url_pic'] . 'poll/';

$_CONF['quiz.dir_image'] = $_CONF['core.dir_pic'] . 'quiz' PHPFOX_DS;
$_CONF['quiz.url_image'] = $_CONF['core.url_pic'] . 'quiz/';

$_CONF['egift.dir_egift'] = $_CONF['core.dir_pic'] . 'egift' PHPFOX_DS;
$_CONF['egift.url_egift'] = $_CONF['core.url_pic'] . 'egift/';

$_CONF['marketplace.dir_image'] = $_CONF['core.dir_pic'] . 'marketplace' PHPFOX_DS;
$_CONF['marketplace.url_image'] = $_CONF['core.url_pic'] . 'marketplace/';

$_CONF['app.dir_image'] = $_CONF['core.dir_pic'] . 'app' PHPFOX_DS;
$_CONF['app.url_image'] = $_CONF['core.url_pic'] . 'app/';

$_CONF['event.dir_image'] = $_CONF['core.dir_pic'] . 'event' PHPFOX_DS;
$_CONF['event.url_image'] = $_CONF['core.url_pic'] . 'event/';

$_CONF['pages.dir_image'] = $_CONF['core.dir_pic'] . 'pages' PHPFOX_DS;
$_CONF['pages.url_image'] = $_CONF['core.url_pic'] . 'pages/';

$_CONF['group.dir_image'] = $_CONF['core.dir_pic'] . 'group' PHPFOX_DS;
$_CONF['group.url_image'] = $_CONF['core.url_pic'] . 'group/';

$_CONF['share.dir_image'] = $_CONF['core.dir_pic'] . 'bookmark' PHPFOX_DS;
$_CONF['share.url_image'] = $_CONF['core.url_pic'] . 'bookmark/';

$_CONF['music.dir'] = $_CONF['core.dir_file'] . 'music' PHPFOX_DS;
$_CONF['music.url'] = $_CONF['core.url_file'] . 'music/';

$_CONF['music.dir_image'] = $_CONF['core.dir_pic'] . 'music' PHPFOX_DS;
$_CONF['music.url_image'] = $_CONF['core.url_pic'] . 'music/';

$_CONF['video.dir'] = $_CONF['core.dir_file'] . 'video' PHPFOX_DS;
$_CONF['video.url'] = $_CONF['core.url_file'] . 'video/';

$_CONF['video.dir_image'] = $_CONF['core.dir_pic'] . 'video' PHPFOX_DS;
$_CONF['video.url_image'] = $_CONF['core.url_pic'] . 'video/';

$_CONF['ad.dir_image'] = $_CONF['core.dir_pic'] . 'ad' PHPFOX_DS;
$_CONF['ad.url_image'] = $_CONF['core.url_pic'] . 'ad/';

$_CONF['subscribe.dir_image'] = $_CONF['core.dir_pic'] . 'subscribe' PHPFOX_DS;
$_CONF['subscribe.url_image'] = $_CONF['core.url_pic'] . 'subscribe/';

$_CONF['css.dir_cache'] = $_CONF['core.dir_file'] . 'css' PHPFOX_DS;
$_CONF['css.url_cache'] = $_CONF['core.url_file'] . 'css/';

$_CONF['chat.dir_cache'] = $_CONF['core.dir_file'] . 'chat' PHPFOX_DS;
$_CONF['chat.url_cache'] = $_CONF['core.url_file'] . 'chat/';

$_CONF['core.dir_watermark'] = $_CONF['core.dir_pic'] . 'watermark' PHPFOX_DS;
$_CONF['core.url_watermark'] = $_CONF['core.url_pic'] . 'watermark/';

$_CONF['core.dir_icon'] = $_CONF['core.dir_pic'] . 'icon' PHPFOX_DS;
$_CONF['core.url_icon'] = $_CONF['core.url_pic'] . 'icon/';

/* Static URLS */
$_CONF['core.dir_static'] = PHPFOX_DIR 'static/';

$_CONF['core.url_static2'] = $_CONF['core.path'] . 'static/';
$_CONF['core.url_static'] = $cdnRootUrl '/static/';

$_CONF['core.url_static_script'] = $_CONF['core.url_static2'] . 'jscript/';
$_CONF['core.url_static_css'] = $_CONF['core.url_static'] . 'style/';
$_CONF['core.url_static_image'] = $_CONF['core.url_static'] . 'image/';
$_CONF['core.url_misc'] = $_CONF['core.url_static_image'] . 'misc/';

// Name of the thumbnail directory
$_CONF['core.url_thumb'] = 'thumb/';


?>


Explanation :
The line
$_CONF['core.url_static'] = $cdnRootUrl . '/static/';

has been changed to point to the serverB.
The line
$_CONF['core.url_static_script'] = $_CONF['core.url_static2'] . 'jscript/';
will still point to the the main server ,serverA , due to some javascript problems if serverB is used to server files in the /static/jscript/ directory.

*****Important****
You MUST enable PHP support on serverB IF you enable gzip compression.
To get maximum performance using this setup , I would recommend enabling php on serverB , so that gzip feature can be used. Enable CSS and JS Caching&Compression in the adminCP .
This way 90+% of your JS and CSS from modules and core will all be compressed into 2 files (1 for CSS and the other for JS ).
This would be a a huge performance gain.
Save the file , clear the cache and the test it out.
View the page HTML source to verify that files are actually being server from serverB.

P.S The reason for copying the /include directory is so that the file /static/gzip.php can use the phpFox server settings .


2. Memcache vs File cache
I won't go into details on how to install and configure memcached as it's beyond the scope of this tutorial. I'm just going to share my experience here.
I'd been using memcached instead of the default file cache before hoping the performance would be better. But I didn't get any performance gain or at least i didn't notice any. In fact , I found out my system became even slower . Reverting to file-based caching made my site load quicker .
After doing some research on this anomaly , I came up with the conclusion that memcached server , being hosted on another server , must have been suffering from I/O latency especially as many cache records were being read (I had over 100K cache entries in memcached sometimes, thus ,if it took 1ms to get a record, it'd take 1000 x 1ms = 1000ms to get 1000 records. ).
Thus, *In My Setup* it's still faster executing mysql queries and using file-based caching instead of memcached. This may NOT be true for everyone.
I'm suspecting that memcached PHP binaries may not have been optimized properly and/or the memcached server implementation maybe be faulty. These are all speculations .

I'd thus advise anyone using memcached to carry out some preliminary tests before making deployment.
I hope this tutorial has been informative to you.
Feel free to share your feedback.