Facebook PHP SDK Deficiency in handling cluster environment

For casual developers, you may be just deploying your Facebook app to your web hosting server.  However, if you get large applications that overload your server, then you may meed to deploy your Facebook app to a server cluster.

In this is the case, then please note that you may be facing problems due to a deficient in the PHP SDK.

In you take a look at the code of the getCurrentUrl() function, you will notice that the $currentUrl is formatted by using code

$currentUrl = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

However, for server cluster, the variable $_SERVER[‘HTTP_HOST’] may not be always equal to what the user see. You should use the code:

$origServer = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST'];
$currentUrl = $protocol . $origServer . $_SERVER['REQUEST_URI'];

Hope this helps.

This entry was posted in Development Tips, PHP SDK Demystified and tagged . Bookmark the permalink.

Leave a Reply

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