Skip to content

Commit

Permalink
[2.x] Fixes missing server software environment variable (#101)
Browse files Browse the repository at this point in the history
* Adds missing server software environment variable

* Update Octane.php

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
nunomaduro and taylorotwell authored Oct 5, 2021
1 parent dd63851 commit 27711d8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Runtime/Octane/Octane.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class Octane implements Client
*/
public static function boot($basePath, $databaseSessionPersist = false, $databaseSessionTtl = 0)
{
self::ensureServerSoftware('vapor');

$databaseSessionTtl = (int) $databaseSessionTtl;

static::$worker = tap(new Worker(
Expand Down Expand Up @@ -184,6 +186,8 @@ public static function terminate()
static::$worker->terminate();

static::$worker = null;

self::ensureServerSoftware(null);
}
}

Expand Down Expand Up @@ -241,4 +245,16 @@ public function error(Throwable $e, Application $app, Request $request, RequestC
fwrite(STDERR, $e->getMessage());
}
}

/**
* Ensures the given software name is set globally.
*
* @param string|null $software
* @return void
*/
protected static function ensureServerSoftware($software)
{
$_ENV['SERVER_SOFTWARE'] = $software;
$_SERVER['SERVER_SOFTWARE'] = $software;
}
}
6 changes: 6 additions & 0 deletions tests/Feature/OctaneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,10 @@ public function test_on_error()

Event::assertDispatched(WorkerErrorOccurred::class);
}

public function test_server_software()
{
self::assertSame('vapor', $_ENV['SERVER_SOFTWARE']);
self::assertSame('vapor', $_SERVER['SERVER_SOFTWARE']);
}
}

0 comments on commit 27711d8

Please sign in to comment.