File: TestServer.php

package info (click to toggle)
thrift 0.22.0-3
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 29,588 kB
  • sloc: cpp: 103,295; java: 26,996; ansic: 21,793; pascal: 15,437; php: 12,823; cs: 10,610; python: 9,733; javascript: 9,274; ruby: 8,316; erlang: 7,360; sh: 5,569; makefile: 4,203; perl: 3,351; yacc: 1,145; xml: 1,079; ml: 962; lisp: 664; lex: 322
file content (87 lines) | stat: -rw-r--r-- 2,752 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php

error_reporting(E_ALL);

require_once __DIR__ . '/../../vendor/autoload.php';

$opts = getopt(
    'h::',
    [
        'port::',
        'domain-socket::',
        'pipe::',
        'server-type::',
        'transport::',
        'protocol::',
        'multiplex::',
        'abstract-namespace::',
        'ssl::',
        'zlib::',
        'processor-events::',
        'workers::',
    ]
);
if (isset($opts['h'])) {
    echo <<<HELP
      -h | --help                  produce help message
      --port=arg (9090)            Port number to listen
      --domain-socket=arg          Unix Domain Socket (e.g. /tmp/ThriftTest.thrift)
      --pipe=arg                   Windows Named Pipe (e.g. MyThriftPipe)
      --server-type=arg (simple)   type of server, "simple", "thread-pool",
                                   "threaded", or "nonblocking"
      --transport=arg (buffered)   transport: buffered, framed, http, anonpipe, zlib
      --protocol=arg (binary)      protocol: binary, compact, header, json
      --multiplex                  Add TMultiplexedProtocol service name "ThriftTest"
      --abstract-namespace         Create the domain socket in the Abstract Namespace
                                   (no connection with filesystem pathnames)
      --ssl                        Encrypted Transport using SSL
      --zlib                       Wrapped Transport using Zlib
      --processor-events           processor-events
      -n=arg | --workers=arg (=4)  Number of thread pools workers. Only valid for
                                   thread-pool server type
HELP;
    exit(0);
}

$port = $opts['port'] ?? 9090;
$transport = $opts['transport'] ?? 'buffered';


$loader = new Thrift\ClassLoader\ThriftClassLoader();
$loader->registerDefinition('ThriftTest', __DIR__ . '/../../lib/php/test/Resources/packages/phpcm');
$loader->register();

$sslOptions = \stream_context_create(
    [
        'ssl' => [
            'verify_peer' => false,
            'verify_peer_name' => false,
        ],
    ]
);

require_once __DIR__ . '/Handler.php';

switch ($transport) {
    case 'framed':
        $serverTransportFactory = new \Thrift\Factory\TFramedTransportFactory();
        break;
    default:
        $serverTransportFactory = new \Thrift\Factory\TTransportFactory();
}

$serverTransport = new \Thrift\Server\TServerSocket('localhost', $port);
$handler = new Handler();
$processor = new ThriftTest\ThriftTestProcessor($handler);

$server = new \Thrift\Server\TSimpleServer(
    $processor,
    $serverTransport,
    $serverTransportFactory,
    $serverTransportFactory,
    new \Thrift\Factory\TBinaryProtocolFactory(),
    new \Thrift\Factory\TBinaryProtocolFactory()
);

echo "Starting the Test server...\n";
$server->serve();