Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/FunctionRuntime/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public static function run(): void
{
ColdStartTracker::init();

// OPcache doesn't cache files modified less than 2 seconds before the request started, and with BREF_LOOP_MAX
// the request starts with the process: files written later (e.g. compiled views) would never be cached
if (getenv('BREF_LOOP_MAX') > 1 && get_cfg_var('opcache.file_update_protection') === false) {
ini_set('opcache.file_update_protection', '0');
}

LazySecretsLoader::loadSecretEnvironmentVariables();

Bref::events()->beforeStartup();
Expand Down
53 changes: 53 additions & 0 deletions tests/FunctionRuntime/MainTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php declare(strict_types=1);

namespace Bref\Test\FunctionRuntime;

use Bref\FunctionRuntime\Main;
use Bref\Test\RuntimeTestCase;

class MainTest extends RuntimeTestCase
{
public function setUp(): void
{
parent::setUp();

$_SERVER['LAMBDA_TASK_ROOT'] = __DIR__ . '/../Runtime/Fixtures';
putenv('_HANDLER=foo.php');
}

public function tearDown(): void
{
unset($_SERVER['LAMBDA_TASK_ROOT']);
putenv('_HANDLER');
putenv('BREF_LOOP_MAX');
ini_restore('opcache.file_update_protection');

parent::tearDown();
}

public function test BREF_LOOP_MAX disables OPcache file update protection()
{
putenv('BREF_LOOP_MAX=100');

try {
Main::run();
} catch (\Throwable) {
// Needed because `run()` is an infinite loop and will fail eventually
}

$this->assertSame('0', ini_get('opcache.file_update_protection'));
}

public function test OPcache settings are unchanged without BREF_LOOP_MAX()
{
$fileUpdateProtection = ini_get('opcache.file_update_protection');

try {
Main::run();
} catch (\Throwable) {
// Needed because `run()` is an infinite loop and will fail eventually
}

$this->assertSame($fileUpdateProtection, ini_get('opcache.file_update_protection'));
}
}
Loading