<?php<liu21st@gmail.com>
namespace think\worker;
use Workerman\Worker;
abstract class Server
{
protected $worker;
protected $socket = '';
protected $protocol = 'http';
protected $host = '0.0.0.0';
protected $port = '2346';
protected $option = [];
protected $context = [];
protected $event = ['onWorkerStart', 'onConnect', 'onMessage', 'onClose', 'onError', 'onBufferFull', 'onBufferDrain', 'onWorkerReload'];
public function __construct()
{
$this->worker = new Worker($this->socket ?: $this->protocol . '://' . $this->host . ':' . $this->port, $this->context);
if (!empty($this->option)) {
foreach ($this->option as $key => $val) {
$this->worker->$key = $val;
}
}
foreach ($this->event as $event) {
if (method_exists($this, $event)) {
$this->worker->$event = [$this, $event];
}
}
$this->init();
Worker::runAll();
}
protected function init()
{
}
public function __set($name, $value)
{
$this->worker->$name = $value;
}
public function __call($method, $args)
{
call_user_func_array([$this->worker, $method], $args);
}
}