Created
October 13, 2012 10:06
-
-
Save musaid/3884032 to your computer and use it in GitHub Desktop.
recording the jobs touched and the number of tries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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