/** * Run * @param */ public function Run() { parent::run(); $this->get_access_token(); //获取access_token $conect = $this->openConnction(); $this->responseMsg(); $this->closeConnection(); }
public function run() { parent::run(); $conect = $this->openConnction(); if (!$conect) { return $this->_response; } else { $this->access_token = $this->get_access_token(); switch ($this->_requestParameters->type) { case "USER_GET_TIKETS": $this->GetTikets(); break; case "USER_RAISE_TIKET": $this->RaiseTiket(); break; case "USER_GET_LOCATION": $this->GetLocation(); break; case "USER_SEND_TIKET": $this->SendTiket(); break; case "USER_SEND_MESSAGE": $this->sendMessage(); break; case "USER_SEND_NEWS": $this->send_News(); break; case "USER_SEND_TEMPLATE": $this->send_template_message(); break; case "USER_GET_TEMPLATE": $this->get_template(); break; case "USER_GET_INDUSTRY": $this->get_industry(); break; case "USER_SET_INDUSTRY": $this->set_industry(); break; default: $this->_response["success"] = false; $this->_response["errmsg"] = "Invalid Operation"; } } $this->closeConnection(); }
public function run() { parent::run(); if (!$this->openConnction()) { return $this->_response; } else { switch ($this->_requestParameters->type) { case "USER_LOGIN": $this->login(); break; case "USER_Search_Balance": $this->SearchBalance(); break; case "USER_SEARCH_DETAIL": $this->SearchDetail(); break; case "USER_REGISTER": $this->Register(); break; case "USER_HAS_LOGIN": $this->hasLogin(); break; case "USER_TRANSFER": $this->transfer(); break; case "USER_THIRD_TRANSFER": $this->third_transfer(); break; case "USER_LOGOUT": $this->Logout(); break; case "USER_SEARCH_INDEX": $this->searchIndex(); break; case "USER_SEARCH_STOCK": $this->searchStock(); break; default: $this->_response["success"] = false; $this->_response["errmsg"] = "Invalid Params"; } } $this->closeConnection(); }
public function run() { parent::run(); switch ($this->_requestParameters->type) { case "USER_SEARCH_INDEX": $this->searchIndex(); break; case "USER_SEARCH_STOCK": $this->searchStock(); break; case "USER_SEARCH_OPTION": $this->searchOption(); break; default: $this->_response["success"] = false; $this->_response["errmsg"] = "Invalid Params"; } // if (!$this->openConnction()) { // return $this->_response; // } else { // // } $this->closeConnection(); }
$out .= " ({$msg})"; } $this->log("{$out}"); // updating users list $this->sendAll(function ($server, $cli) { return new Message('users', $server->getUsersList($cli)); }); } public function getUsersList(Client $skip = null) { $users = ['you']; foreach ($this->clients as $cli) { if ($skip == null || $cli->id != $skip->id) { $users[] = $cli->id; } } return $users; } public function log($msg) { $date = date('Y-m-d H:i:s'); echo "[{$date}] {$msg}\n"; } } $options = ['address' => '0.0.0.0', 'port' => 8000]; $server = new Server($options); try { $server->run(); } catch (Exception $e) { $server->log('Unable to connect: ' . $e->getMessage()); }
/** * TwIRCd - Twitter IRC Server * * This file is part of TwIRCd. * * TwIRCd is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3 of the License. * * TwIRCd is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with TwIRCd; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * @package Core * @version $Revision$ * @license http://www.gnu.org/licenses/gpl-3.0.txt GPL */ namespace TwIRCd; require __DIR__ . '/env.php'; const VERSION = '0.0.1'; $logger = new Logger\StdOut(); $twircd = new Server($logger, new Irc\Server($logger, '127.0.0.1', 13377), new Mapper\Ident($logger), 'post '); $twircd->run();
die; } // Die if the request is an option method. if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'OPTIONS') { errorResult('Request method OPTION is not supported.'); } if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') { if (($input = @file_get_contents('php://input')) === FALSE) { errorResult('POST query without postbody.'); } } elseif (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'GET') { if (!isset($_GET['payload']) || ($input = $_GET['payload']) === FALSE) { errorResult('GET query without "payload" param.'); } } else { errorResult('Can not detect the HTTP method of incoming query.'); } try { $query = Query::parse($input); } catch (ServerException $e) { errorResult($e->getMessage()); } $server = new Server(); // services require_once 'api/sample.php'; $sampleService = new SampleService(); $server->register('sample', $sampleService); // run $result = $server->run($query); echo Result::stringify($result); ob_flush();
function lg($msg) { $msg = date('c') . " {$msg}\n"; file_put_contents('/tmp/b', $msg, FILE_APPEND | LOCK_EX); } class Server { function run() { $serv = new swoole_server("127.0.0.1", 8002); $serv->set(array('timeout' => 1, 'poll_thread_num' => 1, 'worker_num' => 1, 'backlog' => 128, 'max_conn' => 10000, 'dispatch_mode' => 2)); $serv->on('Receive', array($this, 'onReceive')); $serv->on('Close', array($this, 'onClose')); //swoole_server_addtimer($serv, 2); #swoole_server_addtimer($serv, 10); $serv->start(); } function onClose($serv, $fd, $from_id) { // 关闭会导致连接的客户端报错 } function onReceive($serv, $fd, $from_id, $data) { //lg($data); echo $data . "\n"; $serv->send($fd, $data); } } $serv = new Server(); $serv->run();
{ $log = date("Y-m-d H:i:s") . " {$log} \n"; file_put_contents($this->logFilePath, $log, FILE_APPEND | LOCK_EX); echo date("Y-m-d H:i:s") . " {$log} \n"; } /** * set log file path of task * @param stirng $path */ protected function setLogFilePath($path) { $this->logFilePath = $path; } protected function writeFile($filename, $content) { $file = fopen("{$filename}", "a"); while (1) { if (flock($file, LOCK_EX)) { fwrite($file, $content); flock($file, LOCK_UN); fclose($file); break; } else { usleep(1000); } } } } $obj = new Server(); $obj->run();