Skip to content

Commit 7d85c97

Browse files
committed
Honor runtime memory during Playground startup
1 parent 66ae688 commit 7d85c97

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

packages/runtime-playground/src/playground-cli-runner.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,16 +332,33 @@ function runtimeBootstrapPhpIniEntries(spec: RuntimeCreateSpec): Record<string,
332332
}
333333

334334
function pluginRuntimeBootstrapPhpIniEntries(spec: RuntimeCreateSpec): Record<string, string> | undefined {
335-
return pluginRuntimePhpEntries(spec, "bootstrapIniEntries")
335+
const memoryLimit = pluginRuntimePhpMemoryLimit(spec)
336+
return {
337+
...(memoryLimit ? { memory_limit: memoryLimit } : {}),
338+
...(pluginRuntimePhpEntries(spec, "bootstrapIniEntries") ?? {}),
339+
}
336340
}
337341

338342
function pluginRuntimePhpIniEntries(spec: RuntimeCreateSpec): Record<string, string> | undefined {
343+
const memoryLimit = pluginRuntimePhpMemoryLimit(spec)
339344
return {
340345
...DEFAULT_RUNTIME_PHP_INI_ENTRIES,
346+
...(memoryLimit ? { memory_limit: memoryLimit } : {}),
341347
...(pluginRuntimePhpEntries(spec, "iniEntries") ?? {}),
342348
}
343349
}
344350

351+
function pluginRuntimePhpMemoryLimit(spec: RuntimeCreateSpec): string | undefined {
352+
const pluginRuntime = spec.metadata?.recipe && typeof spec.metadata.recipe === "object" && !Array.isArray(spec.metadata.recipe)
353+
? (spec.metadata.recipe as { inputs?: { pluginRuntime?: unknown } }).inputs?.pluginRuntime
354+
: undefined
355+
const php = pluginRuntime && typeof pluginRuntime === "object" && !Array.isArray(pluginRuntime)
356+
? (pluginRuntime as { php?: Record<string, unknown> }).php
357+
: undefined
358+
const memoryLimit = php?.memoryLimit
359+
return typeof memoryLimit === "string" && /^[0-9]+[KMG]?$/.test(memoryLimit) ? memoryLimit : undefined
360+
}
361+
345362
function pluginRuntimePhpEntries(spec: RuntimeCreateSpec, key: "iniEntries" | "bootstrapIniEntries"): Record<string, string> | undefined {
346363
const pluginRuntime = spec.metadata?.recipe && typeof spec.metadata.recipe === "object" && !Array.isArray(spec.metadata.recipe)
347364
? (spec.metadata.recipe as { inputs?: { pluginRuntime?: unknown } }).inputs?.pluginRuntime

tests/playground-cli-runner-bootstrap-ini.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ try {
4949
inputs: {
5050
pluginRuntime: {
5151
php: {
52-
iniEntries: { memory_limit: "512M" },
52+
memoryLimit: "2G",
53+
iniEntries: { max_input_vars: 2048 },
5354
bootstrapIniEntries: { "opcache.file_cache": "/tmp/opcache" },
5455
},
5556
},
@@ -75,7 +76,7 @@ try {
7576
assert.equal(calls[0].wordpressInstallMode, "do-not-attempt-installing")
7677
assert.equal(calls[0].skipSqliteSetup, true)
7778
assert.equal(shouldUseProgrammaticPlaygroundRunner(spec), false)
78-
assert.deepEqual(calls[0].phpIniEntries, { memory_limit: "512M" })
79+
assert.deepEqual(calls[0].phpIniEntries, { memory_limit: "2G", max_input_vars: "2048" })
7980
assert.deepEqual(calls[0].phpExtension, ["/tmp/sodium/manifest.json"])
8081
const sharedPhpIniPath = calls[0]["mount-before-install"]?.[0]?.hostPath
8182
const sharedAutoPrependPath = calls[0]["mount-before-install"]?.[1]?.hostPath
@@ -85,7 +86,7 @@ try {
8586
assert.match(sharedPhpIni, /opcache\.file_cache = \/tmp\/opcache/)
8687
// The runtime default memory ceiling stays high enough for collect_artifacts to
8788
// base64 heavy snapshot/declared-artifact files without a hard PHP fatal.
88-
assert.match(sharedPhpIni, /memory_limit=512M/)
89+
assert.match(sharedPhpIni, /memory_limit = 2G/)
8990
assert.match(sharedPhpIni, /auto_prepend_file=\/internal\/shared\/wp-codebox-auto-prepend\.php/)
9091
const sharedAutoPrepend = await readFile(sharedAutoPrependPath as string, "utf8")
9192
assert.match(sharedAutoPrepend, /require_once '\/internal\/shared\/auto_prepend_file\.php'/)

0 commit comments

Comments
 (0)