Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…for ensuring proper loading
  • Loading branch information...
commit 9ebd14b05ab5eeba0179b921d6f91f9cb17c44f4 1 parent 40e202c
@brianlmoon authored
Showing with 44 additions and 0 deletions.
  1. +44 −0 pecl-worker-classes/Avg.php
View
44 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;
+
+ }
+
+}
+
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.