本文整理汇总了PHP中Server::start方法的典型用法代码示例。如果您正苦于以下问题:PHP Server::start方法的具体用法?PHP Server::start怎么用?PHP Server::start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Server
的用法示例。
在下文中一共展示了Server::start方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: hproseserver_call
function hproseserver_call(swoole_process $worker)
{
define('APPLICATION_PATH', dirname(__DIR__) . "/application");
define('MYPATH', dirname(APPLICATION_PATH));
$application = new Yaf_Application(dirname(APPLICATION_PATH) . "/conf/application.ini");
$application->bootstrap();
$config_obj = Yaf_Registry::get("config");
$hprose_config = $config_obj->hprose->toArray();
$server = new Server("tcp://" . $hprose_config['ServerIp'] . ":" . $hprose_config['port']);
$server->setErrorTypes(E_ALL);
$server->setDebugEnabled();
$server->addFunction('zys');
$server->start();
}
示例2: onTask
echo "Client {$fd} close connection\n";
}
public function onTask($serv, $task_id, $from_id, $data)
{
$data_arr = json_decode($data, true);
$source_data = $data_arr['source'];
$source = explode(' ', $source_data);
$trainid = $source[1];
$command = './tools/preprocess.py --id ' . $trainid;
exec($command);
return "Task {$task_id}'s result";
}
public function onFinish($serv, $task_id, $data)
{
}
/**
* send message by swoole
* @param string $content the command
* return boolean true if shut down the swoole_client successfully
*/
private function sendtagbyswoole($content)
{
$client = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_SYNC);
$client->connect('127.0.0.1', 8888, 0.5, 0);
$client->send($content);
return $client->close();
}
}
$server = new Server();
$server->start();
示例3: curl_setopt_array
<?php
namespace Ftob\LeaderBoardBundle\Tests;
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/Server.php';
Server::start();
register_shutdown_function(function () {
Server::stop();
});
// Override curl_setopt_array() to get the last set curl options
namespace GuzzleHttp\Handler;
function curl_setopt_array($handle, array $options)
{
if (!empty($_SERVER['curl_test'])) {
$_SERVER['_curl'] = $options;
} else {
unset($_SERVER['_curl']);
}
\curl_setopt_array($handle, $options);
}
示例4: onFinish
*/
public function onFinish($server, $task_id, $data)
{
}
/**
* 用户关闭连接
* @param $server
* @param $fd
*/
public function onClose($server, $fd)
{
echo "{$fd} closed" . PHP_EOL;
$username = $this->clients[$fd];
//释放客户,利用锁进行数据同步
$this->lock->lock();
unset($this->clients[$fd]);
$this->lock->unlock();
//有用户名的用户则推送离开消息
if (!empty($username)) {
$frame = new stdClass();
$frame->fd = $fd;
$frame->data = array('username' => $username, 'message' => $username . '离开聊天室', 'type' => 1, 'status' => 1, 'time' => date('H:i:s'));
$frame->clients = $this->clients;
// 发送离开消息
$server->task($frame);
}
}
}
$Server = new Server();
$Server->start();
示例5: Server
<?php
require __DIR__ . '/Server.php';
$setting = (require __DIR__ . '/config.php');
$host = array_shift($setting);
$port = array_shift($setting);
$serv = new Server($host, $port, $setting);
$serv->start();
示例6: json_decode
$this->data = json_decode(file_get_contents('php://input'), true);
// Раскодируем JSON
// Подключаемся к базе данных
$this->conn = new mysqli(self::SQL_SERVER, self::SQL_USER, self::SQL_PASS, self::SQL_DB);
if ($this->conn->connect_error) {
if (DEBUG) {
die('Ошибка соединения: ' . mysql_error());
}
}
}
private function __destruct()
{
// Закрываем соединение с базой
$this->conn->close();
}
// Задаем значение в базе данных
private function setValue($value_name, $value_text)
{
return $this->conn->query('UPDATE ajax_table SET value_text = \'' . $value_text . '\' WHERE value_name = \'' . $value_name . '\'');
}
// Получаем значение из базы данных
private function getValue($value_name)
{
$res = $this->conn->query("SELECT value_text FROM ajax_table WHERE value_name='{$value_name}'");
$row = $res->fetch_object();
return $row->value_text;
}
}
// Server::start()->process()->display();
Server::start()->process()->result();
示例7: array
#!/usr/bin/php -q
<?php
require_once 'light/Server.php';
require_once 'light/JsonEncoder.php';
error_reporting(E_ALL);
set_time_limit(0);
ob_implicit_flush();
$args = $_SERVER['argv'];
$flags = array();
foreach ($args as $arg) {
if (preg_match('/^-/', $arg)) {
$flags[preg_replace('/^-/', '', $arg)] = true;
}
}
if (empty($args[1]) || empty($args[2])) {
echo "\nUsage: xmlserver.php HOSTIP PORT (-log)\n";
exit;
}
$ip = $args[1];
$port = $args[2];
Message::$encoder = new JsonEncoder();
$mySocketServer = new Server($ip, $port);
$mySocketServer->start();
示例8: stdClass
$x2 = new stdClass();
/*
$a = require 'req01.php';
$b = require 'req02.php';
$c = require 'req03.php';
$d = require 'req04.php';
*/
$GLOBALS['this']->test = 'test';
$GLOBALS['this']->x1 = $x1;
$GLOBALS['this']->x2 = $x2;
//var_dump(array_keys($GLOBALS));
var_dump(get_class($GLOBALS['this']));
usleep(10000);
echo PHP_EOL . '[Application] dumping $GLOBALS[\'server\']:' . PHP_EOL;
var_dump($GLOBALS['server']);
usleep(10000);
echo PHP_EOL . '[Application] dumping $GLOBALS[\'this\']:' . PHP_EOL;
var_dump($GLOBALS['this']);
}
}
$a = [];
for ($i = 0; $i < 100; $i++) {
$a[] = new stdClass();
}
$server = new Server();
$server->start(PTHREADS_INHERIT_ALL | PTHREADS_ALLOW_GLOBALS);
usleep(5000);
echo PHP_EOL . '[GLOBAL] dumping $server:' . PHP_EOL;
$server->x1 = 'asdf';
var_dump($server);
echo "finished script..." . PHP_EOL;