Skip to content

Instantly share code, notes, and snippets.

@openprojdev
Created June 18, 2013 09:29
Show Gist options
  • Save openprojdev/5803965 to your computer and use it in GitHub Desktop.
Save openprojdev/5803965 to your computer and use it in GitHub Desktop.
PHP CDN hostnames based on circular array shift, useful to distribute static content via multi hostnames serving the same content i.e increase concurrent downloads by browsers
$cdnHosts = array( //declared in an global config
'h1.hostname.com',
'h2.hostname.com',
'h3.hostname.com',
'h4.hostname.com'
);
/**
*
* cdnHostNames
*
* @params array $cdnHosts containing all the hostnames
* @return string the first string value of the circular shifted array
*/
function cdnHostNames(&$cdnHosts) {
$cdnHosts = array_merge( array_slice($cdnHosts, 1), array_slice($cdnHosts, 0, 1) ) ;
return $cdnHosts[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment