summaryrefslogblamecommitdiffstats
path: root/application/controllers/GearmanController.php
blob: 5b842b1e200259baecc713e17b2813e41c5452d5 (plain) (tree)
1
2
3
4
5
6
7
8







                                                      








                                                                                        
         

                                     
         
 
         
 
                                        
         


































                                                  










                                                                                                   
                                                                                                                   


                                                                                           
                         
                 


                                                
                                      
                                 





























                                                                       


                                                  

                                                                                    





                                                             
         
 
<?php

class GearmanController extends Zend_Controller_Action
{
	protected $gearmanClient;

	public function init()
	{

		if (Zend_Auth::getInstance()->hasIdentity()) {
			$this->userIDsNamespace = Zend_Session::namespaceGet('userIDs');
			$this->gearmanClient = new GearmanClient();
			$this->gearmanClient->addServer('127.0.0.1');
		} else {
			$this->_helper->redirector('login', 'auth');
			return;
		}
	}

	public function indexAction()
	{

	}

	public function somepingAction()
	{
		$ipArray = array(
			'132.230.4.1',
			'132.230.4.2',
			'132.230.4.3',
			'132.230.4.4',
			'132.230.4.5',
			'132.230.4.6',
			'132.230.4.7',
			'132.230.4.8',
			'132.230.4.9',
			'132.230.4.10',
			'132.230.4.11',
			'132.230.4.12',
			'132.230.4.13',
			'132.230.4.14',
			'132.230.4.15',
			'132.230.4.16',
			'132.230.4.17',
			'132.230.4.18',
			'132.230.4.19',
			'132.230.4.20',
			'132.230.4.21',
			'132.230.4.22',
			'132.230.4.23',
			'132.230.4.24',
			'132.230.4.25',
			'132.230.4.26',
			'132.230.4.27',
			'132.230.4.28',
			'132.230.4.29',
			'132.230.4.30',
		);

		$ipString = json_encode($ipArray);

		$result = $this->gearmanClient->do("somePing", $ipString, 'somePing');
		if (! $this->gearmanClient->runTasks())
		{
			echo "ERROR " . $gmc->error() . "\n";
			exit;
		}
		$resultsExp = explode('; ', $result);
		if(is_array($resultsExp)) {
			foreach($resultsExp as $result) {
				$resultDecode = json_decode($result);
				$resultDecode->rawoutput = sprintf('%s', $resultDecode->rawoutput);
				$resultDecode->rawoutput = str_replace("\n", "<br />\t", $resultDecode->rawoutput);
				$resultDecode->alive = sprintf('%s', $resultDecode->alive);
				$resultDecode->rc = sprintf('%s', $resultDecode->rc);
				$results[] = $resultDecode;
			}
		}
		$this->view->results = $results;
	}

	public function bootAction() {
		$clients = array(
		array('id' => '1', 'ip' =>'132.230.4.1', 'mac' =>''),
		array('id' => '2', 'ip' =>'132.230.4.2', 'mac' =>''),
		array('id' => '3', 'ip' =>'132.230.4.3', 'mac' =>''),
		array('id' => '4', 'ip' =>'132.230.4.4', 'mac' =>''),
		array('id' => '5', 'ip' =>'132.230.4.5', 'mac' =>''),
		array('id' => '6', 'ip' =>'132.230.4.6', 'mac' =>''),
		array('id' => '7', 'ip' =>'132.230.4.7', 'mac' =>''),
		array('id' => '8', 'ip' =>'132.230.4.8', 'mac' =>''),
		array('id' => '9', 'ip' =>'132.230.4.9', 'mac' =>''),
		array('id' => '10', 'ip' =>'132.230.4.10', 'mac' =>''),
		array('id' => '11', 'ip' =>'132.230.4.11', 'mac' =>''),
		array('id' => '12', 'ip' =>'132.230.4.12', 'mac' =>''),
		array('id' => '13', 'ip' =>'132.230.4.13', 'mac' =>''),
		array('id' => '14', 'ip' =>'132.230.4.14', 'mac' =>''),
		array('id' => '15', 'ip' =>'132.230.4.15', 'mac' =>''),
		array('id' => '16', 'ip' =>'132.230.4.16', 'mac' =>''),
		array('id' => '17', 'ip' =>'132.230.4.17', 'mac' =>''),
		array('id' => '18', 'ip' =>'132.230.4.18', 'mac' =>''),
		array('id' => '19', 'ip' =>'132.230.4.19', 'mac' =>''),
		array('id' => '20', 'ip' =>'132.230.4.20', 'mac' =>''),
		array('id' => '21', 'ip' =>'132.230.4.21', 'mac' =>''),
		array('id' => '22', 'ip' =>'132.230.4.22', 'mac' =>''),
		array('id' => '23', 'ip' =>'132.230.4.23', 'mac' =>''),
		array('id' => '24', 'ip' =>'132.230.4.24', 'mac' =>''),
		array('id' => '25', 'ip' =>'132.230.4.25', 'mac' =>''),
		array('id' => '26', 'ip' =>'132.230.4.26', 'mac' =>''),
		array('id' => '27', 'ip' =>'132.230.4.27', 'mac' =>''),
		array('id' => '28', 'ip' =>'132.230.4.28', 'mac' =>''),
		array('id' => '29', 'ip' =>'132.230.4.29', 'mac' =>''),
		array('id' => '30', 'ip' =>'132.230.4.30', 'mac' =>''),
		);
			
		$ipString = json_encode($clients);
		$id = 1;
		$result = $this->gearmanClient->do("boot", $ipString, 'boot' . $id);
		if (! $this->gearmanClient->runTasks())
		{
			echo "ERROR " . $gmc->error() . "\n";
			exit;
		}
		$this->view->result = $result;
	}
}