Skip to content

Instantly share code, notes, and snippets.

@benjaminmullard
Created February 6, 2015 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benjaminmullard/9667cc564d6036fdf707 to your computer and use it in GitHub Desktop.
Save benjaminmullard/9667cc564d6036fdf707 to your computer and use it in GitHub Desktop.
CodeIgniter helper functions
<?php if (!defined('BASEPATH')) { exit; }
if (!function_exists('generate_uuid')) {
/**
* Generate a universally unique ID that can be used for sharding.
*
* @param integer $shard_id The ID to shard by.
* @param integer $seq Incrementing sequence for the database table.
* @return string Universally unique ID.
*/
function generate_uuid($shard_id=0, $seq=0) {
return floor((microtime(TRUE) * 1000) - APP_EPOCH_MS) << 23 |
($shard_id % APP_NUM_SHARDS) << 10 |
($seq % 1024);
}
}
/* End of file custom_helper.php */
/* Location: ./application/helpers/custom_helper.php */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment