Files
thrift/test/php/TestServer.php
Volodymyr Panivko f69b418f1f THRIFT-6023: Add HTTP transport support to PHP cross-tests (#3515)
Client: php

PHP was the only major-language entry stuck on buffered/framed sockets
while Python, Go, Node, C++, Java, Lua, Dart, JS, D, and Haskell already
declared http in their cross-test transports.

Server (test/php/TestServer.php + HttpRouter.php + HttpServer.php):
- On --transport=http, TestServer pcntl_exec()s into 'php -S' with
  HttpRouter.php as the router. The chameleon HttpRouter dispatches on
  PHP_SAPI: cli launches php -S with itself as the per-request handler;
  cli-server invokes HttpServer.
- HttpServer reads php://input via TMemoryBuffer, peeks the message
  type, and for ONEWAY sends an empty HTTP 200 immediately while
  forking the handler so strict clients (Java) measure fast oneway
  latency. Sync path echoes the processor's response bytes.
- protocols.php centralises the protocol-name -> TProtocolFactory
  dispatch, shared between the socket entry point and the cli-server
  router.

Client (test/php/TestClient.php):
- Adds an http branch that uses TPsrHttpClient (THRIFT-6010) against
  http://127.0.0.1:$port/. Drops the duplicate makeProtocol() helper
  in favour of thrift_test_protocol_factory()->getProtocol(), removes
  the unused $host argv parsing, and normalises the file to PSR-12.

composer.json: adds guzzlehttp/guzzle ^7.8 to require-dev so PSR-18
discovery resolves a real client at cross-test time.

test/tests.json: adds 'http' to PHP server and client transports.

test/known_failures_Linux.json: lists php-cpp_*_http-ip (cpp THttpClient
does not handle Connection: close between calls — tracked as
THRIFT-6060) and nodejs-php_*_http-ip (Node http server mounts /test,
not /, matching the existing cpp-/d-/go-nodejs known failures).

Generated-by: Claude Opus 4.7
2026-06-02 08:22:23 +02:00

87 lines
2.9 KiB
PHP

<?php
error_reporting(E_ALL);
require_once __DIR__ . '/../../vendor/autoload.php';
require_once __DIR__ . '/protocols.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, json, accel
--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 = (int) ($opts['port'] ?? 9090);
$transport = $opts['transport'] ?? 'buffered';
$protocol = $opts['protocol'] ?? 'binary';
// HTTP transport: delegate to HttpRouter (its CLI-launcher branch execs into
// `php -S` with HttpRouter itself as the per-request handler).
if ($transport === 'http') {
require __DIR__ . '/HttpRouter.php';
return;
}
$loader = new \Thrift\ClassLoader\ThriftClassLoader();
$loader->registerDefinition('ThriftTest', __DIR__ . '/gen-php-classmap');
$loader->register();
require_once __DIR__ . '/Handler.php';
$serverTransportFactory = match ($transport) {
'framed' => new \Thrift\Factory\TFramedTransportFactory(),
default => new \Thrift\Factory\TTransportFactory(),
};
$protocolFactory = thrift_test_protocol_factory($protocol);
// `localhost` may resolve to an IPv6-only listener in newer PHP/runtime combinations,
// while some cross-test clients still connect via 127.0.0.1. Bind explicitly to IPv4.
$serverTransport = new \Thrift\Server\TServerSocket('127.0.0.1', $port);
$processor = new \ThriftTest\ThriftTestProcessor(new \Handler());
$server = new \Thrift\Server\TSimpleServer(
$processor,
$serverTransport,
$serverTransportFactory,
$serverTransportFactory,
$protocolFactory,
$protocolFactory,
);
echo "Starting the Test server...\n";
$server->serve();