public function start($setting = array()) { Trace::info(str_repeat('-', 100)); Trace::info(str_pad('[ ShadowSocks Swoole PHP ]', 100, ' ', STR_PAD_BOTH)); Trace::info(str_pad("IP:" . self::$conf['ip'] . " PORT:" . self::$conf['port'], 100, ' ', STR_PAD_BOTH)); Trace::info(str_pad("PassWord : "******"Encode :" . self::$conf['method'], 100, ' ', STR_PAD_BOTH)); Trace::info(str_repeat('-', 100)); $default = ['timeout' => 1, 'poll_thread_num' => 1, 'worker_num' => 4, 'backlog' => 128, 'dispatch_mode' => 2]; $setting = array_merge($default, $setting); $this->serv->set($setting); $this->serv->start(); }
public function send($data = null) { //锁定状态写入队列 if (!empty($data)) { $this->queue->push($data); } if ($this->reconn) { Trace::debug("*********cli {$this->fd} reconn \n"); $this->cli->connect($this->conf['ip'], $this->conf['port']); $this->reconn = false; $this->lock = true; } if ($this->queue->isEmpty()) { $this->lock = false; } elseif (!$this->lock) { $this->lock = true; $data = $this->queue->shift(); Trace::debug("*********cli {$this->fd} send " . strlen($data) . "\n==================\n" . substr($data, 0, 50) . "...\n=============="); Trace::info(sprintf("Host: %-25s %s", $this->conf['host'], strstr($data, "\n", true))); //;'Host:' . $this->conf['host'] . strstr($data, "\n", true) $this->cli->send($data); } }