Skip to content

Instantly share code, notes, and snippets.

@musaid
Created October 13, 2012 10:06
Show Gist options
  • Save musaid/3884032 to your computer and use it in GitHub Desktop.
Save musaid/3884032 to your computer and use it in GitHub Desktop.
recording the jobs touched and the number of tries
<?php
$touched = array(
'pidone' => array('ref' => 'somerefno', 'tries' => 1, 'timestamp' => 1350111444),
'pidtwo' => array('ref' => 'anotherrefno', 'tries' => 2, 'timestamp' => 1350111527)
);
$pid = 'pidtwo';
$ref = 'refthree';
function touched(&$touched, $pid, $ref) {
if (isset($touched[$pid])) {
if ($touched[$pid]['tries'] >= 3)
return false;
else if ((time() - $touched[$pid]['timestamp']) > (24 * 60 * 60))
return false;
else
$touched[$pid]['tries'] = $touched[$pid]['tries'] + 1;
}
else
$touched = array_merge($touched, array($pid => array('ref' => $ref, 'tries' => 1, 'timestamp' => time())));
return true;
}
var_dump(touched($touched, $pid, $ref));
var_dump($touched);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment