January 2012

Is your Redmine running very slow? Shift to Mongrel from Webrick

Tags: | |

Some time back, we had installed Redmine a project management web application built in Rails on our server. It worked smoothly for a while but then it started getting slower. In the last few days, it slowed down to the extent that it took ages (over a minute) to load any page.

First I thought it might be due to load on server but it wa snot the cause, After some research on Redmine website, I successfully resolved the issue by changing the web server from Webrick to Mongrel.

Earlier, we were using the webrick server by starting it like this:

 
root@server [~]# cd to redmine directory
root@server [/home/rails_apps/redmine]#ruby script/server webrick -e production -d

Here’s how you can resolve by running mongrel:

 
root@server [~]# cd to redmine directory
root@server [/home/rails_apps/redmine]#mongrel_rails start --environment=production -d

As soon as you shift to mongrel, you will see the Redmine running even better than before it got slow. Just make sure you add the ‘-d’ detachment parameter at the end otherwise it will stop the server if you would exit the shell.

Hope that helps.

Cheers!

Simple Way to Keep Your Web Portal Pages Fresh by Rotating Content Blocks using PHP

gallery

For larger websites and web portals, keeping their website layout look fresh is one of the most important factors. You may be posting lot of new content in your website but if it;s layout remains same, users might not feel any difference.

One great way to show visitors new layout to see each time they visit your site, apart from the content, is to rotate different content blocks. Every web portals has different content blocks which are dynamic and show content from each sections or whatever they hold. You can easily rotate these content blocks which usually are the php include files.

For instance you have a well structured web portal where you include different include files to display content from different sections. Of course each section content is fetched from database and is dynamic but by rearranging the include files by changing their order dynamically based on the date, web site layout will bring a fresh look and feel where each content block will rotate.

Just define the the include files in an array (or you can even fetch this from database) like this:

 
// This function will rotate the array values as per offset value
function array_rotate($array, $shift) {
    $shift %= count($array); 
    if($shift < 0) $shift += count($array);
    return array_merge(array_slice($array, $shift, NULL, true), array_slice($array, 0, $shift, true));
}
 
 
//define the content blocks files
$content_blocks = array('/block1.php','/block2.php', '/block3.php','/block4.php', '/block5.php');
 
//find the offset using today's date 
$block_offset = date('j') % count($content_blocks); 
 
//rotate the array to re-arrange content blocks
$content_blocks = array_rotate($content_blocks, $block_offset);
 
//print the content blocks here by including them in the page one by one
 
foreach($content_blocks as $k){
 
if(file_exists(dirname(__FILE__).$k)) include(dirname(__FILE__).$k);
 
	}

So each day, your website home page or (any other page) will display content blocks in new order, bringing it a fresh look everyday. Of course, you can make content of each block file also dynamic.

Hope that helps.

Cheers!

How to check Facebook Page Liked by User, Like-Gate Facebook iFrame Tab using PHP Graph API

Tags:
facebook-graph-api

These days, every business wants more and more ‘Likes’ for their Facebook pages if their Facebook application supports its own custom tab. And this is kinda becoming the basic requirement for every such Facebook app these days so here’s how you can achieve that using Graph API PHP SDK. This helps us choosing the content which we show to the user and if he has not liked the page yet, we can ask the user to do that first.

 
require 'facebook.php';
 
$app_id = "your app id";
$app_secret = "your app secret";
$facebook = new Facebook(array(
    'appId' => $app_id,
    'secret' => $app_secret,
    'cookie' => true,
));
 
$signed_request = $facebook->getSignedRequest();
 
$like_status = $signed_request["page"]["liked"];
 
if ($like_status == 1){
echo 'User likes this page';
}
else{
echo 'User doesn\'t like this page';
}

You can check all the other data by printing the $signed_request array like this:

 
echo '<pre>';
print_r($signed_request);
echo '

‘;

Among other info, you can also retrieve the page ID of the current Facebook page using the above information from array. $signed_request['page']['id'] can help you in showing tab specific content.

Hope that helps.

Cheers!

Resolve JInstaller::install: Failed Joomla Components and Modules Installation Errors

Tags:
joomla

If you are facing trouble in instillation of Joomla components and modules, and getting errors like * It was not possible to copy the selected file.
* JInstaller::install: Failed to copy file:
, you need to give write permissions to yuor components and modules directories.

To resolve this, go to Joomla Administrator > Help > System Info > Directory Permissions

All of the following directories must be writable for Joomla to install components, modules and themes.

Directory Permissions
Directory Status
 
administrator/backups/ Writable
administrator/components/ Writable
administrator/language/ Writable
administrator/language/en-GB/ Writable
administrator/language/nl-NL/ Writable
administrator/modules/ Writable
administrator/templates/ Writable
components/ Writable
images/ Writable
images/banners/ Writable
images/stories/ Writable
language/ Writable
language/en-GB/ Writable
language/nl-NL/ Writable
language/pdf_fonts/ Writable
media/ Writable
modules/ Writable
plugins/ Writable
plugins/content/ Writable
plugins/editors/ Writable
plugins/editors-xtd/ Writable
plugins/search/ Writable
plugins/system/ Writable
plugins/user/ Writable
plugins/xmlrpc/ Writable
templates/ Writable
Cache Directory /home/user/public_html/cache/ Writable
Cache Directory /home/user/public_html/administrator/cache/ Writable
Log Directory ($log_path) /home/user/public_html/logs/ Writable
Temp Directory ($tmp_path) /home/user/public_html/tmp/ Writable

Hope that helps.

Dynamically Resizing Facebook Canvas (iFrame) Apps to Remove Scrollbars

Tags:
facebook-graph-api

All new Facebook applications are now iFrame apps. But when you check your app using iFrame inside Facebook, horizontal and vertical scroll bars may appear in the iFrame if the content exceeds height and width of the
canvas. Luckily, Facebook provides a ready to use method to dynamically re-sizing of iFrame inside it.

Step 1

If you want to remove the horizontal and vertical scrollbars from your iFrame Facebook app, GO to your application developer page > app settings and in the “Edit settings” section of your app and change your “IFrame Size” to “Auto-resize” NOT “Show scrollbars.”

Step 2

Open your config file where you have defined other settings for your app and add following code:

 
<div id="fb-root"></div>
<script type="text/javascript">
    window.fbAsyncInit = function() {
        //Your app id must be added there to work
        FB.init({appId: 'your_app_id', status: true, cookie: true, xfbml: true});
        //Resize the iframe when needed
        FB.Canvas.setAutoResize();
    };
 
    //Load the JavaScript SDK asynchronously
    (function() {
        var e = document.createElement('script'); e.async = true;
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        document.getElementById('fb-root').appendChild(e);
    }());
</script>

Now your iframe FB App should resize automatically depending on the content. You can see the documentation of setAutoResize() method on Facebook wiki.

Hope that helps.

Cheers!

Get Facebook User’s Affiliations, Network Information Using Facebook Graph API

Tags:
facebook-graph-api

Facebook Graph API $me object does not provide user’s network info. To access FB user’s networks/affiliations information, you need to use FQL like this:

 
$fql  =  'SELECT affiliations, name FROM user WHERE uid = '.$me['id'];
 
//or use this query for standard_user_info table
//$fql = 'SELECT affiliations, name FROM standard_user_info WHERE uid = '.$me['id']; 
 
$param  =   array(
       'method'     => 'fql.query',
        'query'     => $fql,
      'callback'    => ''
);
$affiliations   =   $facebook->api($param);
 
echo '<pre>';
print_r($affiliations);
echo '

‘;

Hope that helps.