Volodymyr Panivko | 68139d1 | 2024-03-19 23:14:07 +0100 | [diff] [blame] | 1 | <?php |
| 2 | |
| 3 | error_reporting(E_ALL); |
| 4 | |
| 5 | require_once __DIR__ . '/../../vendor/autoload.php'; |
| 6 | |
| 7 | $opts = getopt( |
| 8 | 'h::', |
| 9 | [ |
| 10 | 'port::', |
| 11 | 'domain-socket::', |
| 12 | 'pipe::', |
| 13 | 'server-type::', |
| 14 | 'transport::', |
| 15 | 'protocol::', |
| 16 | 'multiplex::', |
| 17 | 'abstract-namespace::', |
| 18 | 'ssl::', |
| 19 | 'zlib::', |
| 20 | 'processor-events::', |
| 21 | 'workers::', |
| 22 | ] |
| 23 | ); |
| 24 | if (isset($opts['h'])) { |
| 25 | echo <<<HELP |
| 26 | -h | --help produce help message |
| 27 | --port=arg (9090) Port number to listen |
| 28 | --domain-socket=arg Unix Domain Socket (e.g. /tmp/ThriftTest.thrift) |
| 29 | --pipe=arg Windows Named Pipe (e.g. MyThriftPipe) |
| 30 | --server-type=arg (simple) type of server, "simple", "thread-pool", |
| 31 | "threaded", or "nonblocking" |
| 32 | --transport=arg (buffered) transport: buffered, framed, http, anonpipe, zlib |
| 33 | --protocol=arg (binary) protocol: binary, compact, header, json |
| 34 | --multiplex Add TMultiplexedProtocol service name "ThriftTest" |
| 35 | --abstract-namespace Create the domain socket in the Abstract Namespace |
| 36 | (no connection with filesystem pathnames) |
| 37 | --ssl Encrypted Transport using SSL |
| 38 | --zlib Wrapped Transport using Zlib |
| 39 | --processor-events processor-events |
| 40 | -n=arg | --workers=arg (=4) Number of thread pools workers. Only valid for |
| 41 | thread-pool server type |
| 42 | HELP; |
| 43 | exit(0); |
| 44 | } |
| 45 | |
| 46 | $port = $opts['port'] ?? 9090; |
| 47 | $transport = $opts['transport'] ?? 'buffered'; |
| 48 | |
| 49 | |
| 50 | $loader = new Thrift\ClassLoader\ThriftClassLoader(); |
| 51 | $loader->registerDefinition('ThriftTest', __DIR__ . '/../../lib/php/test/Resources/packages/phpcm'); |
| 52 | $loader->register(); |
| 53 | |
| 54 | $sslOptions = \stream_context_create( |
| 55 | [ |
| 56 | 'ssl' => [ |
| 57 | 'verify_peer' => false, |
| 58 | 'verify_peer_name' => false, |
| 59 | ], |
| 60 | ] |
| 61 | ); |
| 62 | |
| 63 | require_once __DIR__ . '/Handler.php'; |
| 64 | |
| 65 | switch ($transport) { |
| 66 | case 'framed': |
| 67 | $serverTransportFactory = new \Thrift\Factory\TFramedTransportFactory(); |
| 68 | break; |
| 69 | default: |
| 70 | $serverTransportFactory = new \Thrift\Factory\TTransportFactory(); |
| 71 | } |
| 72 | |
| 73 | $serverTransport = new \Thrift\Server\TServerSocket('localhost', $port); |
| 74 | $handler = new Handler(); |
| 75 | $processor = new ThriftTest\ThriftTestProcessor($handler); |
| 76 | |
| 77 | $server = new \Thrift\Server\TSimpleServer( |
| 78 | $processor, |
| 79 | $serverTransport, |
| 80 | $serverTransportFactory, |
| 81 | $serverTransportFactory, |
| 82 | new \Thrift\Factory\TBinaryProtocolFactory(), |
| 83 | new \Thrift\Factory\TBinaryProtocolFactory() |
| 84 | ); |
| 85 | |
| 86 | echo "Starting the Test server...\n"; |
| 87 | $server->serve(); |