diff options
author | Wolfy-J <[email protected]> | 2018-09-23 14:00:08 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-09-23 14:00:08 +0300 |
commit | f7d64d8e8592951ed5a0f0b06db608bc73786ea2 (patch) | |
tree | 1bdef1618288221495f1f38bb528e71cca907e2e /php-src | |
parent | 4815ebb760672c7fa541c941d7f47cd316656020 (diff) |
- new directory structure
- singular exception
- starting exception deprecation
Diffstat (limited to 'php-src')
26 files changed, 0 insertions, 1052 deletions
diff --git a/php-src/Exceptions/RoadRunnerException.php b/php-src/Exceptions/RoadRunnerException.php deleted file mode 100644 index fa7b8da3..00000000 --- a/php-src/Exceptions/RoadRunnerException.php +++ /dev/null @@ -1,13 +0,0 @@ -<?php -/** - * High-performance PHP process supervisor and load balancer written in Go - * - * @author Wolfy-J - */ - -namespace Spiral\RoadRunner\Exceptions; - -class RoadRunnerException extends \RuntimeException -{ - -}
\ No newline at end of file diff --git a/php-src/PSR7Client.php b/php-src/PSR7Client.php deleted file mode 100644 index e8d93fe8..00000000 --- a/php-src/PSR7Client.php +++ /dev/null @@ -1,158 +0,0 @@ -<?php -/** - * High-performance PHP process supervisor and load balancer written in Go - * - * @author Wolfy-J - */ - -namespace Spiral\RoadRunner; - -use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\ServerRequestInterface; -use Zend\Diactoros; - -/** - * Manages PSR-7 request and response. - */ -class PSR7Client -{ - /** - * @varWorker - */ - private $worker; - - /** - * @param Worker $worker - */ - public function __construct(Worker $worker) - { - $this->worker = $worker; - } - - /** - * @return Worker - */ - public function getWorker(): Worker - { - return $this->worker; - } - - /** - * @return ServerRequestInterface|null - */ - public function acceptRequest() - { - $body = $this->worker->receive($ctx); - if (empty($body) && empty($ctx)) { - // termination request - return null; - } - - if (empty($ctx = json_decode($ctx, true))) { - // invalid context - return null; - } - - parse_str($ctx['rawQuery'], $query); - - $bodyStream = 'php://input'; - $parsedBody = null; - if ($ctx['parsed']) { - $parsedBody = json_decode($body, true); - } elseif ($body != null) { - $bodyStream = new Diactoros\Stream("php://memory", "rwb"); - $bodyStream->write($body); - } - - $_SERVER = $this->configureServer($ctx); - - $request = new Diactoros\ServerRequest( - $_SERVER, - $this->wrapUploads($ctx['uploads']), - $ctx['uri'], - $ctx['method'], - $bodyStream, - $ctx['headers'], - $ctx['cookies'], - $query, - $parsedBody, - $ctx['protocol'] - ); - - if (!empty($ctx['attributes'])) { - foreach ($ctx['attributes'] as $key => $value) { - $request = $request->withAttribute($key, $value); - } - } - - return $request; - } - - /** - * Send response to the application server. - * - * @param ResponseInterface $response - */ - public function respond(ResponseInterface $response) - { - $headers = $response->getHeaders(); - if (empty($headers)) { - // this is required to represent empty header set as map and not as array - $headers = new \stdClass(); - } - - $this->worker->send($response->getBody(), json_encode([ - 'status' => $response->getStatusCode(), - 'headers' => $headers - ])); - } - - /** - * Returns altered copy of _SERVER variable. Sets ip-address, - * request-time and other values. - * - * @param array $ctx - * @return array - */ - protected function configureServer(array $ctx): array - { - $server = $_SERVER; - $server['REQUEST_TIME'] = time(); - $server['REQUEST_TIME_FLOAT'] = microtime(true); - $server['REMOTE_ADDR'] = $ctx['attributes']['ipAddress'] ?? $ctx['remoteAddr'] ?? '127.0.0.1'; - - return $server; - } - - /** - * Wraps all uploaded files with UploadedFile. - * - * @param array $files - * - * @return array - */ - private function wrapUploads($files): array - { - if (empty($files)) { - return []; - } - - $result = []; - foreach ($files as $index => $f) { - if (!isset($f['name'])) { - $result[$index] = $this->wrapUploads($f); - continue; - } - - $result[$index] = new Diactoros\UploadedFile( - $f['tmpName'], - $f['size'], - $f['error'], - $f['name'], - $f['mime'] - ); - } - - return $result; - } -}
\ No newline at end of file diff --git a/php-src/Worker.php b/php-src/Worker.php deleted file mode 100644 index 3e013090..00000000 --- a/php-src/Worker.php +++ /dev/null @@ -1,166 +0,0 @@ -<?php -/** - * High-performance PHP process supervisor and load balancer written in Go - * - * @author Wolfy-J - */ - -namespace Spiral\RoadRunner; - -use Spiral\Goridge\Exceptions\GoridgeException; -use Spiral\Goridge\RelayInterface as Relay; -use Spiral\RoadRunner\Exceptions\RoadRunnerException; - -/** - * Accepts connection from RoadRunner server over given Goridge relay. - * - * Example: - * - * $worker = new Worker(new Goridge\StreamRelay(STDIN, STDOUT)); - * while ($task = $worker->receive($context)) { - * $worker->send("DONE", json_encode($context)); - * } - */ -class Worker -{ - // Send as response context to request worker termination - const STOP = '{"stop":true}'; - - /** @var Relay */ - private $relay; - - /** - * @param Relay $relay - */ - public function __construct(Relay $relay) - { - $this->relay = $relay; - } - - /** - * Receive packet of information to process, returns null when process must be stopped. Might - * return Error to wrap error message from server. - * - * @param mixed $header - * - * @return \Error|null|string - * @throws GoridgeException - */ - public function receive(&$header) - { - $body = $this->relay->receiveSync($flags); - - if ($flags & Relay::PAYLOAD_CONTROL) { - if ($this->handleControl($body, $header, $flags)) { - // wait for the next command - return $this->receive($header); - } - - // no context for the termination. - $header = null; - - // Expect process termination - return null; - } - - if ($flags & Relay::PAYLOAD_ERROR) { - return new \Error($body); - } - - return $body; - } - - /** - * Respond to the server with result of task execution and execution context. - * - * Example: - * $worker->respond((string)$response->getBody(), json_encode($response->getHeaders())); - * - * @param string|null $payload - * @param string|null $header - */ - public function send(string $payload = null, string $header = null) - { - if (is_null($header)) { - $this->relay->send($header, Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_NONE); - } else { - $this->relay->send($header, Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_RAW); - } - - $this->relay->send($payload, Relay::PAYLOAD_RAW); - } - - /** - * Respond to the server with an error. Error must be treated as TaskError and might not cause - * worker destruction. - * - * Example: - * - * $worker->error("invalid payload"); - * - * @param string $message - */ - public function error(string $message) - { - $this->relay->send( - $message, - Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_RAW | Relay::PAYLOAD_ERROR - ); - } - - /** - * Terminate the process. Server must automatically pass task to the next available process. - * Worker will receive StopCommand context after calling this method. - * - * Attention, you MUST use continue; after invoking this method to let rr to properly - * stop worker. - * - * @throws GoridgeException - */ - public function stop() - { - $this->send(null, self::STOP); - } - - /** - * Handles incoming control command payload and executes it if required. - * - * @param string $body - * @param mixed $header Exported context (if any). - * @param int $flags - * - * @returns bool True when continue processing. - * - * @throws RoadRunnerException - */ - private function handleControl(string $body = null, &$header = null, int $flags): bool - { - $header = $body; - if (is_null($body) || $flags & Relay::PAYLOAD_RAW) { - // empty or raw prefix - return true; - } - - $p = json_decode($body, true); - if ($p === false) { - throw new RoadRunnerException("invalid task context, JSON payload is expected"); - } - - // PID negotiation (socket connections only) - if (!empty($p['pid'])) { - $this->relay->send( - sprintf('{"pid":%s}', getmypid()), Relay::PAYLOAD_CONTROL - ); - } - - // termination request - if (!empty($p['stop'])) { - return false; - } - - // parsed header - $header = $p; - - return true; - } -}
\ No newline at end of file diff --git a/php-src/tests/broken.php b/php-src/tests/broken.php deleted file mode 100644 index b1a3839e..00000000 --- a/php-src/tests/broken.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php -/** - * @var Goridge\RelayInterface $relay - */ - -use Spiral\Goridge; -use Spiral\RoadRunner; - -$rr = new RoadRunner\Worker($relay); - -while ($in = $rr->receive($ctx)) { - echo undefined_function(); - $rr->send((string)$in); -}
\ No newline at end of file diff --git a/php-src/tests/client.php b/php-src/tests/client.php deleted file mode 100644 index fd5d60be..00000000 --- a/php-src/tests/client.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php - -use Spiral\Goridge; - -ini_set('display_errors', 'stderr'); -require dirname(__DIR__) . "/../vendor/autoload.php"; - -if (count($argv) < 3) { - die("need 2 arguments"); -} - -list($test, $goridge) = [$argv[1], $argv[2]]; - -switch ($goridge) { - case "pipes": - $relay = new Goridge\StreamRelay(STDIN, STDOUT); - break; - - case "tcp": - $relay = new Goridge\SocketRelay("localhost", 9007); - break; - - case "unix": - $relay = new Goridge\SocketRelay( - "sock.unix", - null, - Goridge\SocketRelay::SOCK_UNIX - ); - break; - - default: - die("invalid protocol selection"); -} - -require_once sprintf("%s/%s.php", __DIR__, $test); diff --git a/php-src/tests/delay.php b/php-src/tests/delay.php deleted file mode 100644 index bfde2fc4..00000000 --- a/php-src/tests/delay.php +++ /dev/null @@ -1,18 +0,0 @@ -<?php -/** - * @var Goridge\RelayInterface $relay - */ - -use Spiral\Goridge; -use Spiral\RoadRunner; - -$rr = new RoadRunner\Worker($relay); - -while ($in = $rr->receive($ctx)) { - try { - usleep($in * 1000); - $rr->send(''); - } catch (\Throwable $e) { - $rr->error((string)$e); - } -}
\ No newline at end of file diff --git a/php-src/tests/echo.php b/php-src/tests/echo.php deleted file mode 100644 index ba58ff30..00000000 --- a/php-src/tests/echo.php +++ /dev/null @@ -1,17 +0,0 @@ -<?php -/** - * @var Goridge\RelayInterface $relay - */ - -use Spiral\Goridge; -use Spiral\RoadRunner; - -$rr = new RoadRunner\Worker($relay); - -while ($in = $rr->receive($ctx)) { - try { - $rr->send((string)$in); - } catch (\Throwable $e) { - $rr->error((string)$e); - } -}
\ No newline at end of file diff --git a/php-src/tests/error.php b/php-src/tests/error.php deleted file mode 100644 index ebd3418b..00000000 --- a/php-src/tests/error.php +++ /dev/null @@ -1,13 +0,0 @@ -<?php -/** - * @var Goridge\RelayInterface $relay - */ - -use Spiral\Goridge; -use Spiral\RoadRunner; - -$rr = new RoadRunner\Worker($relay); - -while ($in = $rr->receive($ctx)) { - $rr->error((string)$in); -}
\ No newline at end of file diff --git a/php-src/tests/failboot.php b/php-src/tests/failboot.php deleted file mode 100644 index fa8b96f6..00000000 --- a/php-src/tests/failboot.php +++ /dev/null @@ -1,3 +0,0 @@ -<?php -ini_set('display_errors', 'stderr'); -throw new Error("failboot error");
\ No newline at end of file diff --git a/php-src/tests/head.php b/php-src/tests/head.php deleted file mode 100644 index 4f4e4061..00000000 --- a/php-src/tests/head.php +++ /dev/null @@ -1,17 +0,0 @@ -<?php -/** - * @var Goridge\RelayInterface $relay - */ - -use Spiral\Goridge; -use Spiral\RoadRunner; - -$rr = new RoadRunner\Worker($relay); - -while ($in = $rr->receive($ctx)) { - try { - $rr->send("", (string)$ctx); - } catch (\Throwable $e) { - $rr->error((string)$e); - } -}
\ No newline at end of file diff --git a/php-src/tests/http/client.php b/php-src/tests/http/client.php deleted file mode 100644 index 3b6b5dc6..00000000 --- a/php-src/tests/http/client.php +++ /dev/null @@ -1,45 +0,0 @@ -<?php - -use Spiral\Goridge; -use Spiral\RoadRunner; - -ini_set('display_errors', 'stderr'); -require dirname(__DIR__) . "/../../vendor/autoload.php"; - -if (count($argv) < 3) { - die("need 2 arguments"); -} - -list($test, $goridge) = [$argv[1], $argv[2]]; - -switch ($goridge) { - case "pipes": - $relay = new Goridge\StreamRelay(STDIN, STDOUT); - break; - - case "tcp": - $relay = new Goridge\SocketRelay("localhost", 9007); - break; - - case "unix": - $relay = new Goridge\SocketRelay( - "sock.unix", - null, - Goridge\SocketRelay::SOCK_UNIX - ); - break; - - default: - die("invalid protocol selection"); -} - -$psr7 = new RoadRunner\PSR7Client(new RoadRunner\Worker($relay)); -require_once sprintf("%s/%s.php", __DIR__, $test); - -while ($req = $psr7->acceptRequest()) { - try { - $psr7->respond(handleRequest($req, new \Zend\Diactoros\Response())); - } catch (\Throwable $e) { - $psr7->getWorker()->error((string)$e); - } -} diff --git a/php-src/tests/http/cookie.php b/php-src/tests/http/cookie.php deleted file mode 100644 index 196ceee2..00000000 --- a/php-src/tests/http/cookie.php +++ /dev/null @@ -1,334 +0,0 @@ -<?php - -use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\ServerRequestInterface; - -function handleRequest(ServerRequestInterface $req, ResponseInterface $resp): ResponseInterface -{ - $resp->getBody()->write(strtoupper($req->getCookieParams()['input'])); - - return $resp->withAddedHeader( - "Set-Cookie", - (new Cookie('output', 'cookie-output'))->createHeader() - ); -} - -final class Cookie -{ - /** - * The name of the cookie. - * - * @var string - */ - private $name = ''; - /** - * The value of the cookie. This value is stored on the clients computer; do not store sensitive - * information. - * - * @var string|null - */ - private $value = null; - /** - * Cookie lifetime. This value specified in seconds and declares period of time in which cookie - * will expire relatively to current time() value. - * - * @var int|null - */ - private $lifetime = null; - /** - * The path on the server in which the cookie will be available on. - * - * If set to '/', the cookie will be available within the entire domain. If set to '/foo/', - * the cookie will only be available within the /foo/ directory and all sub-directories such as - * /foo/bar/ of domain. The default value is the current directory that the cookie is being set - * in. - * - * @var string|null - */ - private $path = null; - /** - * The domain that the cookie is available. To make the cookie available on all subdomains of - * example.com then you'd set it to '.example.com'. The . is not required but makes it - * compatible with more browsers. Setting it to www.example.com will make the cookie only - * available in the www subdomain. Refer to tail matching in the spec for details. - * - * @var string|null - */ - private $domain = null; - /** - * Indicates that the cookie should only be transmitted over a secure HTTPS connection from the - * client. When set to true, the cookie will only be set if a secure connection exists. - * On the server-side, it's on the programmer to send this kind of cookie only on secure - * connection - * (e.g. with respect to $_SERVER["HTTPS"]). - * - * @var bool|null - */ - private $secure = null; - /** - * When true the cookie will be made accessible only through the HTTP protocol. This means that - * the cookie won't be accessible by scripting languages, such as JavaScript. This setting can - * effectively help to reduce identity theft through XSS attacks (although it is not supported - * by all browsers). - * - * @var bool - */ - private $httpOnly = true; - - /** - * New Cookie instance, cookies used to schedule cookie set while dispatching Response. - * - * @link http://php.net/manual/en/function.setcookie.php - * - * @param string $name The name of the cookie. - * @param string $value The value of the cookie. This value is stored on the clients - * computer; do not store sensitive information. - * @param int $lifetime Cookie lifetime. This value specified in seconds and declares period - * of time in which cookie will expire relatively to current time() - * value. - * @param string $path The path on the server in which the cookie will be available on. - * If set to '/', the cookie will be available within the entire - * domain. - * If set to '/foo/', the cookie will only be available within the - * /foo/ - * directory and all sub-directories such as /foo/bar/ of domain. The - * default value is the current directory that the cookie is being set - * in. - * @param string $domain The domain that the cookie is available. To make the cookie - * available - * on all subdomains of example.com then you'd set it to - * '.example.com'. - * The . is not required but makes it compatible with more browsers. - * Setting it to www.example.com will make the cookie only available in - * the www subdomain. Refer to tail matching in the spec for details. - * @param bool $secure Indicates that the cookie should only be transmitted over a secure - * HTTPS connection from the client. When set to true, the cookie will - * only be set if a secure connection exists. On the server-side, it's - * on the programmer to send this kind of cookie only on secure - * connection (e.g. with respect to $_SERVER["HTTPS"]). - * @param bool $httpOnly When true the cookie will be made accessible only through the HTTP - * protocol. This means that the cookie won't be accessible by - * scripting - * languages, such as JavaScript. This setting can effectively help to - * reduce identity theft through XSS attacks (although it is not - * supported by all browsers). - */ - public function __construct( - string $name, - string $value = null, - int $lifetime = null, - string $path = null, - string $domain = null, - bool $secure = false, - bool $httpOnly = true - ) { - $this->name = $name; - $this->value = $value; - $this->lifetime = $lifetime; - $this->path = $path; - $this->domain = $domain; - $this->secure = $secure; - $this->httpOnly = $httpOnly; - } - - /** - * The name of the cookie. - * - * @return string - */ - public function getName(): string - { - return $this->name; - } - - /** - * The value of the cookie. This value is stored on the clients computer; do not store sensitive - * information. - * - * @return string|null - */ - public function getValue() - { - return $this->value; - } - - /** - * The time the cookie expires. This is a Unix timestamp so is in number of seconds since the - * epoch. In other words, you'll most likely set this with the time function plus the number of - * seconds before you want it to expire. Or you might use mktime. - * - * Will return null if lifetime is not specified. - * - * @return int|null - */ - public function getExpires() - { - if ($this->lifetime === null) { - return null; - } - - return time() + $this->lifetime; - } - - /** - * The path on the server in which the cookie will be available on. - * - * If set to '/', the cookie will be available within the entire domain. If set to '/foo/', - * the cookie will only be available within the /foo/ directory and all sub-directories such as - * /foo/bar/ of domain. The default value is the current directory that the cookie is being set - * in. - * - * @return string|null - */ - public function getPath() - { - return $this->path; - } - - /** - * The domain that the cookie is available. To make the cookie available on all subdomains of - * example.com then you'd set it to '.example.com'. The . is not required but makes it - * compatible with more browsers. Setting it to www.example.com will make the cookie only - * available in the www subdomain. Refer to tail matching in the spec for details. - * - * @return string|null - */ - public function getDomain() - { - return $this->domain; - } - - /** - * Indicates that the cookie should only be transmitted over a secure HTTPS connection from the - * client. When set to true, the cookie will only be set if a secure connection exists. - * On the server-side, it's on the programmer to send this kind of cookie only on secure - * connection - * (e.g. with respect to $_SERVER["HTTPS"]). - * - * @return bool - */ - public function isSecure(): bool - { - return $this->secure; - } - - /** - * When true the cookie will be made accessible only through the HTTP protocol. This means that - * the cookie won't be accessible by scripting languages, such as JavaScript. This setting can - * effectively help to reduce identity theft through XSS attacks (although it is not supported - * by all browsers). - * - * @return bool - */ - public function isHttpOnly(): bool - { - return $this->httpOnly; - } - - /** - * Get new cookie with altered value. Original cookie object should not be changed. - * - * @param string $value - * - * @return Cookie - */ - public function withValue(string $value): self - { - $cookie = clone $this; - $cookie->value = $value; - - return $cookie; - } - - /** - * Convert cookie instance to string. - * - * @link http://www.w3.org/Protocols/rfc2109/rfc2109 - * @return string - */ - public function createHeader(): string - { - $header = [ - rawurlencode($this->name) . '=' . rawurlencode($this->value) - ]; - if ($this->lifetime !== null) { - $header[] = 'Expires=' . gmdate(\DateTime::COOKIE, $this->getExpires()); - $header[] = 'Max-Age=' . $this->lifetime; - } - if (!empty($this->path)) { - $header[] = 'Path=' . $this->path; - } - if (!empty($this->domain)) { - $header[] = 'Domain=' . $this->domain; - } - if ($this->secure) { - $header[] = 'Secure'; - } - if ($this->httpOnly) { - $header[] = 'HttpOnly'; - } - - return join('; ', $header); - } - - /** - * New Cookie instance, cookies used to schedule cookie set while dispatching Response. - * Static constructor. - * - * @link http://php.net/manual/en/function.setcookie.php - * - * @param string $name The name of the cookie. - * @param string $value The value of the cookie. This value is stored on the clients - * computer; do not store sensitive information. - * @param int $lifetime Cookie lifetime. This value specified in seconds and declares period - * of time in which cookie will expire relatively to current time() - * value. - * @param string $path The path on the server in which the cookie will be available on. - * If set to '/', the cookie will be available within the entire - * domain. - * If set to '/foo/', the cookie will only be available within the - * /foo/ - * directory and all sub-directories such as /foo/bar/ of domain. The - * default value is the current directory that the cookie is being set - * in. - * @param string $domain The domain that the cookie is available. To make the cookie - * available - * on all subdomains of example.com then you'd set it to - * '.example.com'. - * The . is not required but makes it compatible with more browsers. - * Setting it to www.example.com will make the cookie only available in - * the www subdomain. Refer to tail matching in the spec for details. - * @param bool $secure Indicates that the cookie should only be transmitted over a secure - * HTTPS connection from the client. When set to true, the cookie will - * only be set if a secure connection exists. On the server-side, it's - * on the programmer to send this kind of cookie only on secure - * connection (e.g. with respect to $_SERVER["HTTPS"]). - * @param bool $httpOnly When true the cookie will be made accessible only through the HTTP - * protocol. This means that the cookie won't be accessible by - * scripting - * languages, such as JavaScript. This setting can effectively help to - * reduce identity theft through XSS attacks (although it is not - * supported by all browsers). - * - * @return Cookie - */ - public static function create( - string $name, - string $value = null, - int $lifetime = null, - string $path = null, - string $domain = null, - bool $secure = false, - bool $httpOnly = true - ): self { - return new self($name, $value, $lifetime, $path, $domain, $secure, $httpOnly); - } - - /** - * @return string - */ - public function __toString(): string - { - return $this->createHeader(); - } -}
\ No newline at end of file diff --git a/php-src/tests/http/data.php b/php-src/tests/http/data.php deleted file mode 100644 index c5e0bab0..00000000 --- a/php-src/tests/http/data.php +++ /dev/null @@ -1,18 +0,0 @@ -<?php - -use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\ServerRequestInterface; - -function handleRequest(ServerRequestInterface $req, ResponseInterface $resp): ResponseInterface -{ - - $data = $req->getParsedBody(); - - ksort($data); - ksort($data['arr']); - ksort($data['arr']['x']['y']); - - $resp->getBody()->write(json_encode($data)); - - return $resp; -}
\ No newline at end of file diff --git a/php-src/tests/http/echo.php b/php-src/tests/http/echo.php deleted file mode 100644 index 7004ada0..00000000 --- a/php-src/tests/http/echo.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php - -use \Psr\Http\Message\ServerRequestInterface; -use \Psr\Http\Message\ResponseInterface; - -function handleRequest(ServerRequestInterface $req, ResponseInterface $resp): ResponseInterface -{ - $resp->getBody()->write(strtoupper($req->getQueryParams()['hello'])); - return $resp->withStatus(201); -}
\ No newline at end of file diff --git a/php-src/tests/http/echoerr.php b/php-src/tests/http/echoerr.php deleted file mode 100644 index da2ff4d8..00000000 --- a/php-src/tests/http/echoerr.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php - -use \Psr\Http\Message\ServerRequestInterface; -use \Psr\Http\Message\ResponseInterface; - -function handleRequest(ServerRequestInterface $req, ResponseInterface $resp): ResponseInterface -{ - error_log(strtoupper($req->getQueryParams()['hello'])); - - $resp->getBody()->write(strtoupper($req->getQueryParams()['hello'])); - return $resp->withStatus(201); -}
\ No newline at end of file diff --git a/php-src/tests/http/env.php b/php-src/tests/http/env.php deleted file mode 100644 index 1e29926f..00000000 --- a/php-src/tests/http/env.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php - -use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\ServerRequestInterface; - -function handleRequest(ServerRequestInterface $req, ResponseInterface $resp): ResponseInterface -{ - $resp->getBody()->write($_SERVER['ENV_KEY']); - return $resp; -}
\ No newline at end of file diff --git a/php-src/tests/http/error.php b/php-src/tests/http/error.php deleted file mode 100644 index 6df0d4b5..00000000 --- a/php-src/tests/http/error.php +++ /dev/null @@ -1,9 +0,0 @@ -<?php - -use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\ServerRequestInterface; - -function handleRequest(ServerRequestInterface $req, ResponseInterface $resp): ResponseInterface -{ - throw new Error("error"); -}
\ No newline at end of file diff --git a/php-src/tests/http/error2.php b/php-src/tests/http/error2.php deleted file mode 100644 index 617b5a3f..00000000 --- a/php-src/tests/http/error2.php +++ /dev/null @@ -1,9 +0,0 @@ -<?php - -use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\ServerRequestInterface; - -function handleRequest(ServerRequestInterface $req, ResponseInterface $resp): ResponseInterface -{ - exit(); -}
\ No newline at end of file diff --git a/php-src/tests/http/header.php b/php-src/tests/http/header.php deleted file mode 100644 index e5b295b6..00000000 --- a/php-src/tests/http/header.php +++ /dev/null @@ -1,11 +0,0 @@ -<?php - -use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\ServerRequestInterface; - -function handleRequest(ServerRequestInterface $req, ResponseInterface $resp): ResponseInterface -{ - $resp->getBody()->write(strtoupper($req->getHeaderLine('input'))); - - return $resp->withAddedHeader("Header", $req->getQueryParams()['hello']); -}
\ No newline at end of file diff --git a/php-src/tests/http/payload.php b/php-src/tests/http/payload.php deleted file mode 100644 index a16984c5..00000000 --- a/php-src/tests/http/payload.php +++ /dev/null @@ -1,13 +0,0 @@ -<?php - -use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\ServerRequestInterface; - -function handleRequest(ServerRequestInterface $req, ResponseInterface $resp): ResponseInterface -{ - // we expect json body - $p = json_decode($req->getBody(), true); - $resp->getBody()->write(json_encode(array_flip($p))); - - return $resp; -}
\ No newline at end of file diff --git a/php-src/tests/http/pid.php b/php-src/tests/http/pid.php deleted file mode 100644 index 1cc322bf..00000000 --- a/php-src/tests/http/pid.php +++ /dev/null @@ -1,11 +0,0 @@ -<?php - -use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\ServerRequestInterface; - -function handleRequest(ServerRequestInterface $req, ResponseInterface $resp): ResponseInterface -{ - $resp->getBody()->write(getmypid()); - - return $resp; -}
\ No newline at end of file diff --git a/php-src/tests/http/upload.php b/php-src/tests/http/upload.php deleted file mode 100644 index 2f7c0b64..00000000 --- a/php-src/tests/http/upload.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php - -use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\ServerRequestInterface; - -function handleRequest(ServerRequestInterface $req, ResponseInterface $resp): ResponseInterface -{ - $files = $req->getUploadedFiles(); - array_walk_recursive($files, function (&$v) { - /** - * @var \Psr\Http\Message\UploadedFileInterface $v - */ - - if ($v->getError()) { - $v = [ - 'name' => $v->getClientFilename(), - 'size' => $v->getSize(), - 'mime' => $v->getClientMediaType(), - 'error' => $v->getError(), - ]; - } else { - $v = [ - 'name' => $v->getClientFilename(), - 'size' => $v->getSize(), - 'mime' => $v->getClientMediaType(), - 'error' => $v->getError(), - 'md5' => md5($v->getStream()->__toString()), - ]; - } - }); - - $resp->getBody()->write(json_encode($files, JSON_UNESCAPED_SLASHES)); - - return $resp; -}
\ No newline at end of file diff --git a/php-src/tests/pid.php b/php-src/tests/pid.php deleted file mode 100644 index a8cfa229..00000000 --- a/php-src/tests/pid.php +++ /dev/null @@ -1,17 +0,0 @@ -<?php -/** - * @var Goridge\RelayInterface $relay - */ - -use Spiral\Goridge; -use Spiral\RoadRunner; - -$rr = new RoadRunner\Worker($relay); - -while ($in = $rr->receive($ctx)) { - try { - $rr->send((string)getmypid()); - } catch (\Throwable $e) { - $rr->error((string)$e); - } -}
\ No newline at end of file diff --git a/php-src/tests/sample.txt b/php-src/tests/sample.txt deleted file mode 100644 index eed7e79a..00000000 --- a/php-src/tests/sample.txt +++ /dev/null @@ -1 +0,0 @@ -sample
\ No newline at end of file diff --git a/php-src/tests/slow-client.php b/php-src/tests/slow-client.php deleted file mode 100644 index 2722868c..00000000 --- a/php-src/tests/slow-client.php +++ /dev/null @@ -1,38 +0,0 @@ -<?php - -use Spiral\Goridge; - -ini_set('display_errors', 'stderr'); -require dirname(__DIR__) . "/../vendor/autoload.php"; - -if (count($argv) < 3) { - die("need 2 arguments"); -} - -list($test, $goridge, $bootDelay, $shutdownDelay) = [$argv[1], $argv[2], $argv[3], $argv[4]]; - -switch ($goridge) { - case "pipes": - $relay = new Goridge\StreamRelay(STDIN, STDOUT); - break; - - case "tcp": - $relay = new Goridge\SocketRelay("localhost", 9007); - break; - - case "unix": - $relay = new Goridge\SocketRelay( - "sock.unix", - null, - Goridge\SocketRelay::SOCK_UNIX - ); - - break; - - default: - die("invalid protocol selection"); -} - -usleep($bootDelay * 1000); -require_once sprintf("%s/%s.php", __DIR__, $test); -usleep($shutdownDelay * 1000);
\ No newline at end of file diff --git a/php-src/tests/stop.php b/php-src/tests/stop.php deleted file mode 100644 index caa485d6..00000000 --- a/php-src/tests/stop.php +++ /dev/null @@ -1,25 +0,0 @@ -<?php -/** - * @var Goridge\RelayInterface $relay - */ - -use Spiral\Goridge; -use Spiral\RoadRunner; - -$rr = new RoadRunner\Worker($relay); - -$used = false; -while ($in = $rr->receive($ctx)) { - try { - if ($used) { - // kill on second attempt - $rr->stop(); - continue; - } - - $used = true; - $rr->send((string)getmypid()); - } catch (\Throwable $e) { - $rr->error((string)$e); - } -}
\ No newline at end of file |