예제 #1
0
 public function sieve($start, $end)
 {
     $primes = array();
     // The sieve is designed to work from 3 and above.
     // We know that "2" is a Prime. So if $start is less than "3", we will prepend the array with "2".
     // But in some cases, "1" is considered prime, and in others not. For our purposes, we've put a setting in the ini file to resolve this issue.
     // The daemon() method on the mediator allows us to import objects/properties from the daemon by name
     if ($start < 3) {
         $settings = $this->mediator->daemon('settings');
         if ($start < 1 && $settings['default']['is_one_prime']) {
             $primes = array(1, 2);
         } else {
             $primes = array(2);
         }
         $start = 3;
     }
     // This is an example of how you can add in custom breakpoints that will be active when you run
     // your daemon with the --debugworkers flag set.
     $this->mediator->breakpoint("Something Is Happeneing in sieve! Oh Noes!");
     for ($i = $start; $i <= $end; $i++) {
         if ($i % 2 != 1) {
             continue;
         }
         $d = 3;
         $x = sqrt($i);
         while ($i % $d != 0 && $d < $x) {
             $d += 2;
         }
         if (($i % $d == 0 && $i != $d) * 1 == 0) {
             $primes[] = $i;
         }
     }
     return $primes;
 }
예제 #2
0
 /**
  * Called on Construct or Init
  * @return void
  */
 public function setup()
 {
     // Read API details from the INI file
     // The ini plugin is created in the Poller::setup() method
     $ini = $this->mediator->daemon('ini');
     $this->uri = $ini['api']['uri'];
     $this->username = $ini['api']['username'];
     $this->token = $ini['api']['token'];
 }