@@ -81,14 +81,20 @@ discard block |
||
| 81 | 81 | /** @var Http $http */ |
| 82 | 82 | $http = $this->container->get(Http::class); |
| 83 | 83 | |
| 84 | - while ($request = $this->worker->waitRequest()) { |
|
| 85 | - try { |
|
| 84 | + while ($request = $this->worker->waitRequest()) |
|
| 85 | + { |
|
| 86 | + try |
|
| 87 | + { |
|
| 86 | 88 | $response = $http->handle($request); |
| 87 | 89 | |
| 88 | 90 | $this->worker->respond($response); |
| 89 | - } catch (\Throwable $e) { |
|
| 91 | + } |
|
| 92 | + catch (\Throwable $e) |
|
| 93 | + { |
|
| 90 | 94 | $this->worker->respond($this->errorToResponse($e)); |
| 91 | - } finally { |
|
| 95 | + } |
|
| 96 | + finally |
|
| 97 | + { |
|
| 92 | 98 | $this->finalizer->finalize(false); |
| 93 | 99 | } |
| 94 | 100 | } |
@@ -102,7 +108,8 @@ discard block |
||
| 102 | 108 | { |
| 103 | 109 | $handler = new HtmlHandler(); |
| 104 | 110 | |
| 105 | - try { |
|
| 111 | + try |
|
| 112 | + { |
|
| 106 | 113 | /** @var SnapshotInterface $snapshot */ |
| 107 | 114 | $snapshot = $this->container->get(SnapshotterInterface::class)->register($e); |
| 108 | 115 | \file_put_contents('php://stderr', $snapshot->getMessage()); |
@@ -110,10 +117,13 @@ discard block |
||
| 110 | 117 | // on demand |
| 111 | 118 | $state = $this->container->get(StateInterface::class); |
| 112 | 119 | |
| 113 | - if ($state !== null) { |
|
| 120 | + if ($state !== null) |
|
| 121 | + { |
|
| 114 | 122 | $handler = $handler->withState($state); |
| 115 | 123 | } |
| 116 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
| 124 | + } |
|
| 125 | + catch (\Throwable | ContainerExceptionInterface $se) |
|
| 126 | + { |
|
| 117 | 127 | \file_put_contents('php://stderr', (string)$e); |
| 118 | 128 | } |
| 119 | 129 | |
@@ -43,8 +43,10 @@ |
||
| 43 | 43 | { |
| 44 | 44 | $state->setTag('php', phpversion()); |
| 45 | 45 | |
| 46 | - if ($this->container->has(DispatcherInterface::class)) { |
|
| 47 | - switch (get_class($this->container->get(DispatcherInterface::class))) { |
|
| 46 | + if ($this->container->has(DispatcherInterface::class)) |
|
| 47 | + { |
|
| 48 | + switch (get_class($this->container->get(DispatcherInterface::class))) |
|
| 49 | + { |
|
| 48 | 50 | case LegacyRrDispatcher::class: |
| 49 | 51 | $state->setTag('dispatcher', 'roadrunner'); |
| 50 | 52 | break; |
@@ -39,15 +39,18 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public function boot(Container $container) |
| 41 | 41 | { |
| 42 | - $container->bindSingleton(RPC::class, function (EnvironmentInterface $env) { |
|
| 42 | + $container->bindSingleton(RPC::class, function (EnvironmentInterface $env) |
|
| 43 | + { |
|
| 43 | 44 | return $this->rpc($env); |
| 44 | 45 | }); |
| 45 | 46 | |
| 46 | - $container->bindSingleton(Worker::class, function (EnvironmentInterface $env) { |
|
| 47 | + $container->bindSingleton(Worker::class, function (EnvironmentInterface $env) |
|
| 48 | + { |
|
| 47 | 49 | return $this->worker($env); |
| 48 | 50 | }); |
| 49 | 51 | |
| 50 | - $container->bindSingleton(MetricsInterface::class, function (RPC $rpc) { |
|
| 52 | + $container->bindSingleton(MetricsInterface::class, function (RPC $rpc) |
|
| 53 | + { |
|
| 51 | 54 | return new Metrics($rpc); |
| 52 | 55 | }); |
| 53 | 56 | } |
@@ -60,21 +63,26 @@ discard block |
||
| 60 | 63 | { |
| 61 | 64 | $conn = $env->get('RR_RPC', self::RPC_DEFAULT); |
| 62 | 65 | |
| 63 | - if (!preg_match('#^([a-z]+)://([^:]+):?(\d+)?$#i', $conn, $parts)) { |
|
| 66 | + if (!preg_match('#^([a-z]+)://([^:]+):?(\d+)?$#i', $conn, $parts)) |
|
| 67 | + { |
|
| 64 | 68 | throw new BootException( |
| 65 | 69 | "Unable to configure RPC connection, invalid DSN given `{$conn}`." |
| 66 | 70 | ); |
| 67 | 71 | } |
| 68 | 72 | |
| 69 | - if (!in_array($parts[1], ['tcp', 'unix'])) { |
|
| 73 | + if (!in_array($parts[1], ['tcp', 'unix'])) |
|
| 74 | + { |
|
| 70 | 75 | throw new BootException( |
| 71 | 76 | "Unable to configure RPC connection, invalid DSN given `{$conn}`." |
| 72 | 77 | ); |
| 73 | 78 | } |
| 74 | 79 | |
| 75 | - if ($parts[1] == 'unix') { |
|
| 80 | + if ($parts[1] == 'unix') |
|
| 81 | + { |
|
| 76 | 82 | $relay = new SocketRelay($parts[2], null, SocketRelay::SOCK_UNIX); |
| 77 | - } else { |
|
| 83 | + } |
|
| 84 | + else |
|
| 85 | + { |
|
| 78 | 86 | $relay = new SocketRelay($parts[2], (int)$parts[3], SocketRelay::SOCK_TCP); |
| 79 | 87 | } |
| 80 | 88 | |
@@ -89,25 +97,31 @@ discard block |
||
| 89 | 97 | { |
| 90 | 98 | $conn = $env->get('RR_RELAY', self::WORKER_DEFAULT); |
| 91 | 99 | |
| 92 | - if ($conn === 'pipes' || empty($conn)) { |
|
| 100 | + if ($conn === 'pipes' || empty($conn)) |
|
| 101 | + { |
|
| 93 | 102 | return new Worker(new StreamRelay(STDIN, STDOUT)); |
| 94 | 103 | } |
| 95 | 104 | |
| 96 | - if (!preg_match('#^([a-z]+)://([^:]+):?(\d+)?$#i', $conn, $parts)) { |
|
| 105 | + if (!preg_match('#^([a-z]+)://([^:]+):?(\d+)?$#i', $conn, $parts)) |
|
| 106 | + { |
|
| 97 | 107 | throw new BootException( |
| 98 | 108 | "Unable to configure Worker connection, invalid DSN given `{$conn}`." |
| 99 | 109 | ); |
| 100 | 110 | } |
| 101 | 111 | |
| 102 | - if (!in_array($parts[1], ['tcp', 'unix'])) { |
|
| 112 | + if (!in_array($parts[1], ['tcp', 'unix'])) |
|
| 113 | + { |
|
| 103 | 114 | throw new BootException( |
| 104 | 115 | "Unable to configure Worker connection, invalid DSN given `{$conn}`." |
| 105 | 116 | ); |
| 106 | 117 | } |
| 107 | 118 | |
| 108 | - if ($parts[1] == 'unix') { |
|
| 119 | + if ($parts[1] == 'unix') |
|
| 120 | + { |
|
| 109 | 121 | $relay = new SocketRelay($parts[2], null, SocketRelay::SOCK_UNIX); |
| 110 | - } else { |
|
| 122 | + } |
|
| 123 | + else |
|
| 124 | + { |
|
| 111 | 125 | $relay = new SocketRelay($parts[2], (int)$parts[3], SocketRelay::SOCK_TCP); |
| 112 | 126 | } |
| 113 | 127 | |
@@ -76,11 +76,13 @@ |
||
| 76 | 76 | |
| 77 | 77 | $kernel->addDispatcher($factory->make(SapiDispatcher::class)); |
| 78 | 78 | |
| 79 | - if (class_exists(PSR7Client::class)) { |
|
| 79 | + if (class_exists(PSR7Client::class)) |
|
| 80 | + { |
|
| 80 | 81 | $kernel->addDispatcher($factory->make(LegacyRrDispatcher::class)); |
| 81 | 82 | } |
| 82 | 83 | |
| 83 | - if (class_exists(PSR7Worker::class)) { |
|
| 84 | + if (class_exists(PSR7Worker::class)) |
|
| 85 | + { |
|
| 84 | 86 | $kernel->addDispatcher($factory->make(RrDispatcher::class)); |
| 85 | 87 | } |
| 86 | 88 | } |
@@ -42,7 +42,8 @@ |
||
| 42 | 42 | */ |
| 43 | 43 | private function isLegacy(): bool |
| 44 | 44 | { |
| 45 | - if (\class_exists(InstalledVersions::class)) { |
|
| 45 | + if (\class_exists(InstalledVersions::class)) |
|
| 46 | + { |
|
| 46 | 47 | $version = InstalledVersions::getVersion('spiral/roadrunner'); |
| 47 | 48 | |
| 48 | 49 | return \str_starts_with($version, '1.'); |
@@ -47,12 +47,17 @@ |
||
| 47 | 47 | { |
| 48 | 48 | $kernel->addDispatcher($jobs); |
| 49 | 49 | |
| 50 | - if (\class_exists(LegacyRPC::class)) { |
|
| 51 | - $container->bindSingleton(QueueInterface::class, function (LegacyRPC $rpc, JobRegistry $registry) { |
|
| 50 | + if (\class_exists(LegacyRPC::class)) |
|
| 51 | + { |
|
| 52 | + $container->bindSingleton(QueueInterface::class, function (LegacyRPC $rpc, JobRegistry $registry) |
|
| 53 | + { |
|
| 52 | 54 | return new JobQueue($rpc, $registry); |
| 53 | 55 | }); |
| 54 | - } else { |
|
| 55 | - $container->bindSingleton(QueueInterface::class, function (RPC $rpc, JobRegistry $registry) { |
|
| 56 | + } |
|
| 57 | + else |
|
| 58 | + { |
|
| 59 | + $container->bindSingleton(QueueInterface::class, function (RPC $rpc, JobRegistry $registry) |
|
| 60 | + { |
|
| 56 | 61 | return new JobQueue($rpc, $registry); |
| 57 | 62 | }); |
| 58 | 63 | } |