davidsteinsland/cakephp-shells

CakePHP utility shells and tasks

1.0.1 2013-10-01 01:24 UTC

README

Build Status Scrutinizer Quality Score Coverage Status

Installing

  • composer install
  • git clone
  • http download

Add to app/Plugin/CakeShells

Examples

A Unique Daemon Worker

class WorkerShell extends AppShell {
	public $tasks = array('CakeShells.Daemon',
		'CakeShells.Pid');
	
	public function initialize() {
		parent::initialize();

		$this->Daemon->setCallback(array($this, 'workerCallback'));
	}

	public function main() {
		$this->Daemon->execute();
	}

	public function workerCallback($pid) {
		$this->Pid->setProcessName("daemon");
		$this->Pid->setPid($pid);
		$this->Pid->execute();

		while(true) {
			// something cool here
		}

		exit;
	}
}

Running a Daemon

class WorkerShell extends AppShell {
	public $tasks = array('CakeShells.Daemon');
	
	public function initialize() {
		parent::initialize();
		$this->Daemon->setCallback(array($this, 'workerCallback'));
	}

	public function main() {
		$this->Daemon->execute();
	}

	public function workerCallback($pid) {
		while(true) {
			// something cool here
		}

		exit;
	}
}

Running a unique file

class WorkerShell extends AppShell {
	public $tasks = array('CakeShells.Pid');
	
	public function main() {
		$this->Pid->setProcessName("WorkerShell");
		$this->Pid->execute();

		// logic here
	}
}