本文整理汇总了PHP中Server类的典型用法代码示例。如果您正苦于以下问题:PHP Server类的具体用法?PHP Server怎么用?PHP Server使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Server类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: forge
public static function forge($request)
{
$server = new Server();
$server->setRequest($request);
$server->parse();
return $server;
}
示例2: main
/**
* Start server
*
* @param string[] args
*/
public static function main(array $args)
{
$stor = new TestingStorage();
$stor->add(new TestingCollection('/', $stor));
$stor->add(new TestingCollection('/.trash', $stor));
$stor->add(new TestingElement('/.trash/do-not-remove.txt', $stor));
$stor->add(new TestingCollection('/htdocs', $stor));
$stor->add(new TestingElement('/htdocs/file with whitespaces.html', $stor));
$stor->add(new TestingElement('/htdocs/index.html', $stor, "<html/>\n"));
$stor->add(new TestingCollection('/outer', $stor));
$stor->add(new TestingCollection('/outer/inner', $stor));
$stor->add(new TestingElement('/outer/inner/index.html', $stor));
$auth = newinstance('lang.Object', array(), '{
public function authenticate($user, $password) {
return ("testtest" == $user.$password);
}
}');
$protocol = newinstance('peer.ftp.server.FtpProtocol', array($stor, $auth), '{
public function onShutdown($socket, $params) {
$this->answer($socket, 200, "Shutting down");
$this->server->terminate= TRUE;
}
}');
isset($args[0]) && $protocol->setTrace(Logger::getInstance()->getCategory()->withAppender(new FileAppender($args[0])));
$s = new Server('127.0.0.1', 0);
try {
$s->setProtocol($protocol);
$s->init();
Console::writeLinef('+ Service %s:%d', $s->socket->host, $s->socket->port);
$s->service();
Console::writeLine('+ Done');
} catch (Throwable $e) {
Console::writeLine('- ', $e->getMessage());
}
}
示例3: __construct
public function __construct(array $options = null)
{
if (!is_array($options)) {
$options = [];
}
if (empty($options["smtpServer"])) {
$hostname = "localhost";
} else {
$hostname = $options["smtpServer"];
}
if ($hostname === "localhost") {
$port = isset($options["local-port"]) ? $options["local-port"] : 25;
} else {
$port = isset($options["port"]) ? $options["port"] : 465;
}
$server = new Server($hostname, $port);
if (!empty($options["username"]) || !empty($options["password"])) {
$server->setCredentials($options["username"], $options["password"]);
}
if (!empty($options["encryption"])) {
$server->setEncryptionMethod($options["encryption"]);
}
if (!empty($options["returnPath"])) {
$server->setReturnPath($options["returnPath"]);
}
parent::__construct($server);
if (!empty($options["fromAddress"])) {
$this->setFromAddress($options["fromAddress"], $options["fromName"]);
}
}
示例4: send
/**
* @param string $url
* @param array $params [optional]
* @return State
*/
function send($url, array $params = null)
{
if ($data = $this->server->send($url, $params)) {
return new State($data);
}
throw new ServerException("Bad Response from Server");
}
示例5: testServerAcceptClient
public function testServerAcceptClient()
{
self::$server->onConnectPeer(function (Peer $peer) {
self::$peer_accepted++;
});
self::$server->listen();
}
示例6: getStreamSrc
public function getStreamSrc($args, $querySep = '&')
{
if (isset($this->{'ServerId'}) and $this->{'ServerId'}) {
$Server = new Server($this->{'ServerId'});
$streamSrc = ZM_BASE_PROTOCOL . '://' . $Server->Hostname() . ZM_PATH_ZMS;
} else {
$streamSrc = ZM_BASE_URL . ZM_PATH_ZMS;
}
$args[] = "monitor=" . $this->{'Id'};
if (ZM_OPT_USE_AUTH) {
if (ZM_AUTH_RELAY == "hashed") {
$args[] = "auth=" . generateAuthHash(ZM_AUTH_HASH_IPS);
} elseif (ZM_AUTH_RELAY == "plain") {
$args[] = "user=" . $_SESSION['username'];
$args[] = "pass=" . $_SESSION['password'];
} elseif (ZM_AUTH_RELAY == "none") {
$args[] = "user=" . $_SESSION['username'];
}
}
if (!in_array("mode=single", $args) && !empty($GLOBALS['connkey'])) {
$args[] = "connkey=" . $GLOBALS['connkey'];
}
if (ZM_RAND_STREAM) {
$args[] = "rand=" . time();
}
if (count($args)) {
$streamSrc .= "?" . join($querySep, $args);
}
return $streamSrc;
}
示例7: testListen_shouldDieIfAttemptsLimit
public function testListen_shouldDieIfAttemptsLimit()
{
$server = new Server($this->createMockStore([[], [], ['test']]));
$server->setDelay(0.1);
$server->setAttemptsLimit(2);
$events = $server->listen(time());
$this->assertEquals([], $events, 'Завершение работы при достижении attemptsLimit');
}
示例8: factory
public static function factory($socket)
{
$context = new \ZMQContext();
$socketDealer = $context->getSocket(\ZMQ::SOCKET_DEALER);
$queueServer = new Server($socketDealer);
$queueServer->setSocket($socket);
return $queueServer;
}
示例9: showAction
public function showAction(Server $server, Player $me, Request $request)
{
if ($server->staleInfo()) {
$server->forceUpdate();
}
if ($request->get('forced') && $me->canEdit($server)) {
$server->forceUpdate();
}
return array("server" => $server);
}
示例10: saveSmd
/**
* Cache a service map description (SMD) to a file
*
* Returns true on success, false on failure
*
* @param string $filename
* @param \Zend\Json\Server\Server $server
* @return boolean
*/
public static function saveSmd($filename, Server $server)
{
if (!is_string($filename) || !file_exists($filename) && !is_writable(dirname($filename))) {
return false;
}
if (0 === @file_put_contents($filename, $server->getServiceMap()->toJson())) {
return false;
}
return true;
}
示例11: console
/**
* Execute commands as console
*
* @param Server $server - pocketmine\Server instance
* @param str[]|str $cmd - commands to execute
* @param bool $show - show commands being executed
*/
public static function console($server, $cmd, $show = false)
{
if (!is_array($cmd)) {
$cmd = [$cmd];
}
foreach ($cmd as $c) {
if ($show) {
$server->getLogger()->info("CMD> {$cmd}");
}
$server->dispatchCommand(new ConsoleCommandSender(), $c);
}
}
示例12: testUpdatePropertiesEventSuccess
function testUpdatePropertiesEventSuccess()
{
$tree = [new SimpleCollection('foo')];
$server = new Server($tree);
$server->on('propPatch', function ($path, PropPatch $propPatch) {
$propPatch->handle(['{DAV:}foo', '{DAV:}foo2'], function () {
return ['{DAV:}foo' => 200, '{DAV:}foo2' => 201];
});
});
$result = $server->updateProperties('foo', ['{DAV:}foo' => 'bar', '{DAV:}foo2' => 'bla']);
$expected = ['{DAV:}foo' => 200, '{DAV:}foo2' => 201];
$this->assertEquals($expected, $result);
}
示例13: update
public function update(Server $server) : Promise
{
switch ($server->state()) {
case Server::STARTED:
$this->watcherId = \Amp\repeat([$this, "updateTime"], 1000);
$this->updateTime();
break;
case Server::STOPPED:
\Amp\cancel($this->watcherId);
$this->watcherId = null;
break;
}
return new Success();
}
示例14: 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();
}
示例15: setPool
public function setPool()
{
$pool = new Pool();
foreach ($this->getConfiguration() as $key => $value) {
$array = new ArrayObject($value);
$server = new Server();
$server->setHost($array->offsetGet(self::SERVER_PROPERTY_HOST))->setPort($array->offsetGet(self::SERVER_PROPERTY_PORT))->setName($key);
if ($array->offsetExists(self::SERVER_PROPERTY_AUTH)) {
$server->setAuth($array->offsetGet(self::SERVER_PROPERTY_AUTH));
}
$pool->attach($server);
}
$this->pool = $pool;
}