Permalink
Browse files

New example Avg class so we hae more than one job in the classes dir …

…for ensuring proper loading
  • Loading branch information...
1 parent 40e202c commit 9ebd14b05ab5eeba0179b921d6f91f9cb17c44f4 @brianlmoon committed Jan 20, 2012
Showing with 44 additions and 0 deletions.
  1. +44 −0 pecl-worker-classes/Avg.php
@@ -0,0 +1,44 @@
+<?php
+
+class Avg {
+
+ private $cache = array();
+
+ private $foo = 0;
+
+ public function run($job, &$log) {
+
+ $workload = $job->workload();
+
+ if(empty($this->cache[$workload])){
+
+ $dat = json_decode($workload, true);
+
+ $sum = 0;
+
+ foreach($dat as $d){
+ $sum+=$d;
+ sleep(1);
+ }
+
+ $avg = $sum / count($dat);
+
+ $this->cache[$workload] = $avg + 0;
+
+ } else {
+
+ $avg = $this->cache[$workload] + 0;
+
+ }
+
+ $log[] = "Answer: ".$avg;
+
+ $this->foo = 1;
+
+ return $avg;
+
+ }
+
+}
+
+?>

0 comments on commit 9ebd14b

Please sign in to comment.