start() 공개 메소드

public start ( )
예제 #1
0
파일: server.php 프로젝트: qieangel2013/zys
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
0
        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
0
<?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
0
     */
    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
0
파일: startup.php 프로젝트: wuxw/swala
<?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
0
        $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
0
#!/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
0
        $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;