Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: laravel/octane
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.2
Choose a base ref
...
head repository: laravel/octane
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.0.3
Choose a head ref
  • 17 commits
  • 8 files changed
  • 7 contributors

Commits on May 27, 2021

  1. Fix typo

    sy-records committed May 27, 2021
    Copy the full SHA
    297e9f5 View commit details
  2. Copy the full SHA
    1d73f6a View commit details
  3. Formatting

    sikhlana committed May 27, 2021
    Copy the full SHA
    505fdda View commit details
  4. Merge pull request #292 from lufei/typo

    Fix typo
    driesvints authored May 27, 2021
    Copy the full SHA
    bc8b836 View commit details
  5. Copy the full SHA
    b39021d View commit details

Commits on May 28, 2021

  1. Display memory usage

    Since the Laravel documentation does not provide how to check for memory leaks, many developers will opt in to use the Laravel debug bar but i found out that the debug bar it has a memory leak, so displaying the memory usage as well as the duration will help to easy spot, memory leaks without external tools.
    stillzombie authored May 28, 2021
    Copy the full SHA
    12bae2d View commit details
  2. fix coding styles

    stillzombie authored May 28, 2021
    Copy the full SHA
    5116a76 View commit details
  3. Fix coding styles

    stillzombie authored May 28, 2021
    Copy the full SHA
    7498291 View commit details
  4. Copy the full SHA
    616e486 View commit details
  5. Copy the full SHA
    67a90f0 View commit details

Commits on May 31, 2021

  1. Copy the full SHA
    54e6677 View commit details
  2. Copy the full SHA
    7260b83 View commit details
  3. formatting

    taylorotwell committed May 31, 2021
    Copy the full SHA
    fdf2703 View commit details
  4. Copy the full SHA
    a6613cc View commit details
  5. Copy the full SHA
    549e122 View commit details

Commits on Jun 1, 2021

  1. Displays memory usage from workers and only on swoole (#304)

    * Displays memory usage from workers and only on swoole
    
    * Apply fixes from StyleCI (#303)
    nunomaduro authored Jun 1, 2021
    Copy the full SHA
    3247a07 View commit details
  2. Update CHANGELOG.md

    driesvints committed Jun 1, 2021
    Copy the full SHA
    ce20157 View commit details
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Release Notes

## [Unreleased](https://github.com/laravel/octane/compare/v1.0.2...1.x)
## [Unreleased](https://github.com/laravel/octane/compare/v1.0.3...1.x)


## [v1.0.3 (2021-06-01)](https://github.com/laravel/octane/compare/v1.0.2...v1.0.3)

### Changed
- Display memory usage ([#297](https://github.com/laravel/octane/pull/297), [#304](https://github.com/laravel/octane/pull/304))

### Fixed
- Fixes issue related to changing non-standard HTTP status codes to 200 OK ([#294](https://github.com/laravel/octane/pull/294))
- Give new application instance to database session handler ([#302](https://github.com/laravel/octane/pull/302))
- Adds SameSite attribute for cookies ([#299](https://github.com/laravel/octane/pull/299))


## [v1.0.2 (2021-05-25)](https://github.com/laravel/octane/compare/v1.0.1...v1.0.2)
12 changes: 8 additions & 4 deletions src/Commands/Concerns/InteractsWithIO.php
Original file line number Diff line number Diff line change
@@ -94,21 +94,24 @@ public function requestInfo($request, $verbosity = null)
$terminalWidth = $this->getTerminalWidth();

$url = parse_url($request['url'], PHP_URL_PATH) ?: '/';

$duration = number_format(round($request['duration'], 2), 2, '.', '');

$memory = isset($request['memory'])
? (number_format($request['memory'] / 1024 / 1204, 2, '.', '').' mb ')
: '';

['method' => $method, 'statusCode' => $statusCode] = $request;

$dots = str_repeat('.', max($terminalWidth - strlen($method.$url.$duration) - 16, 0));
$dots = str_repeat('.', max($terminalWidth - strlen($method.$url.$duration.$memory) - 16, 0));

if (empty($dots) && ! $this->output->isVerbose()) {
$url = substr($url, 0, $terminalWidth - strlen($method.$duration) - 15 - 3).'...';
$url = substr($url, 0, $terminalWidth - strlen($method.$duration.$memory) - 15 - 3).'...';
} else {
$dots .= ' ';
}

$this->output->writeln(sprintf(
' <fg=%s;options=bold>%s </> <fg=cyan;options=bold>%s</> <options=bold>%s</><fg=#6C7280> %s%s ms</>',
' <fg=%s;options=bold>%s </> <fg=cyan;options=bold>%s</> <options=bold>%s</><fg=#6C7280> %s%s%s ms</>',
match (true) {
$statusCode >= 500 => 'red',
$statusCode >= 400 => 'yellow',
@@ -120,6 +123,7 @@ public function requestInfo($request, $verbosity = null)
$method,
$url,
$dots,
$memory,
$duration,
), $this->parseVerbosity($verbosity));
}
1 change: 1 addition & 0 deletions src/Concerns/ProvidesDefaultConfigurationOptions.php
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@ public static function prepareApplicationForNextOperation(): array
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToAuthorizationGate::class,
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToBroadcastManager::class,
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToDatabaseManager::class,
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToDatabaseSessionHandler::class,
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToHttpKernel::class,
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToMailManager::class,
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToNotificationChannelManager::class,
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Laravel\Octane\Listeners;

use Illuminate\Session\DatabaseSessionHandler;

class GiveNewApplicationInstanceToDatabaseSessionHandler
{
/**
* Handle the event.
*
* @param mixed $event
* @return void
*/
public function handle($event): void
{
$handler = $event->sandbox->make('session')->driver()->getHandler();

if (! $handler instanceof DatabaseSessionHandler ||
! method_exists($handler, 'setContainer')) {
return;
}

$handler->setContainer($event->sandbox);
}
}
1 change: 1 addition & 0 deletions src/Stream.php
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ public static function request(string $method, string $url, int $statusCode, flo
'type' => 'request',
'method' => $method,
'url' => $url,
'memory' => memory_get_usage(),
'statusCode' => $statusCode,
'duration' => $duration,
])."\n");
30 changes: 27 additions & 3 deletions src/Swoole/SwooleClient.php
Original file line number Diff line number Diff line change
@@ -19,6 +19,10 @@

class SwooleClient implements Client, ServesStaticFiles
{
const STATUS_CODE_REASONS = [
419 => 'Page Expired',
];

public function __construct(protected int $chunkSize = 1048576)
{
}
@@ -41,7 +45,7 @@ public function marshalRequest(RequestContext $context): array
}

/**
* Detemrine if the request can be served as a static file.
* Determine if the request can be served as a static file.
*
* @param \Illuminate\Http\Request $request
* @param \Laravel\Octane\RequestContext $context
@@ -176,7 +180,11 @@ public function sendResponseHeaders(Response $response, SwooleResponse $swooleRe
}
}

$swooleResponse->status($response->getStatusCode());
if (! is_null($reason = $this->getReasonFromStatusCode($response->getStatusCode()))) {
$swooleResponse->status($response->getStatusCode(), $reason);
} else {
$swooleResponse->status($response->getStatusCode());
}

foreach ($response->headers->getCookies() as $cookie) {
$swooleResponse->{$cookie->isRaw() ? 'rawcookie' : 'cookie'}(
@@ -186,7 +194,8 @@ public function sendResponseHeaders(Response $response, SwooleResponse $swooleRe
$cookie->getPath(),
$cookie->getDomain(),
$cookie->isSecure(),
$cookie->isHttpOnly()
$cookie->isHttpOnly(),
$cookie->getSameSite()
);
}
}
@@ -265,4 +274,19 @@ public function error(Throwable $e, Application $app, Request $request, RequestC
Octane::formatExceptionForClient($e, $app->make('config')->get('app.debug'))
);
}

/**
* Get the HTTP reason clause for non-standard status codes.
*
* @param int $code
* @return string|null
*/
protected function getReasonFromStatusCode(int $code): ?string
{
if (array_key_exists($code, self::STATUS_CODE_REASONS)) {
return self::STATUS_CODE_REASONS[$code];
}

return null;
}
}
9 changes: 6 additions & 3 deletions tests/CommandTest.php
Original file line number Diff line number Diff line change
@@ -54,27 +54,30 @@ public function test_request()
'method' => 'GET',
'url' => 'http://127.0.0.1/welcome',
'statusCode' => '200',
'memory' => 17393560,
'duration' => 10,
]);

$command->requestInfo([
'method' => 'POST',
'url' => 'http://127.0.0.1:8080',
'statusCode' => '404',
'memory' => 20393560,
'duration' => 1234,
]);

$command->requestInfo([
'method' => 'POST',
'url' => 'http://127.0.0.1:8080/'.str_repeat('foo', 100),
'statusCode' => 500,
'memory' => 30393560,
'duration' => 4567854,
]);

$this->assertEquals(<<<'EOF'
200 GET /welcome .................. 10.00 ms
404 POST / ...................... 1234.00 ms
500 POST /foofoofoofoofoofo... 4567854.00 ms
200 GET /welcome ......... 14.11 mb 10.00 ms
404 POST / ............. 16.54 mb 1234.00 ms
500 POST /foofoofo... 24.65 mb 4567854.00 ms

EOF, $output->fetch());
}
19 changes: 19 additions & 0 deletions tests/SwooleClientTest.php
Original file line number Diff line number Diff line change
@@ -181,6 +181,25 @@ public function test_respond_method_send_streamed_response_to_swoole()
}, 200, ['Content-Type' => 'text/html'])));
}

/** @doesNotPerformAssertions @test */
public function test_respond_method_with_laravel_specific_status_code_sends_response_to_swoole()
{
$client = new SwooleClient;

$swooleResponse = Mockery::mock('Swoole\Http\Response');

$swooleResponse->shouldReceive('status')->once()->with(419, 'Page Expired');
$swooleResponse->shouldReceive('header')->once()->with('Cache-Control', 'no-cache, private');
$swooleResponse->shouldReceive('header')->once()->with('Content-Type', 'text/html');
$swooleResponse->shouldReceive('header')->once()->with('Date', Mockery::type('string'));
$swooleResponse->shouldReceive('write')->with('Hello World');
$swooleResponse->shouldReceive('end')->once();

$client->respond(new RequestContext([
'swooleResponse' => $swooleResponse,
]), new OctaneResponse(new Response('Hello World', 419, ['Content-Type' => 'text/html'])));
}

/** @doesNotPerformAssertions @test */
public function test_error_method_sends_error_response_to_swoole()
{