Skip to content

Commit 3418cfa

Browse files
authored
Merge pull request #1872 from Automattic/fix/1838-cloudflare-memory-boot
Run WordPress within Cloudflare Worker memory limits
2 parents fedc677 + a900ae5 commit 3418cfa

14 files changed

Lines changed: 756 additions & 11 deletions

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"wp-codebox:source": "node bin/wp-codebox-source.mjs",
9191
"generate:browser-fanout-aggregation-runtime": "tsx scripts/generate-browser-fanout-aggregation-runtime.ts",
9292
"generate:fanout-aggregation-contract": "tsx scripts/generate-fanout-aggregation-contract-fixture.ts",
93+
"generate:cloudflare-mdi-runtime-bundle": "node scripts/build-cloudflare-mdi-runtime-bundle.mjs",
9394
"smoke": "tsx scripts/run-smoke.ts",
9495
"test:redaction": "tsx tests/redaction.test.ts",
9596
"test:cloudflare-runtime": "tsx tests/cloudflare-runtime.test.ts && node ./node_modules/typescript/bin/tsc -p packages/runtime-cloudflare --noEmit",

packages/runtime-cloudflare/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
This additive integration is the first acceptance gate for [wp-codebox#1838](https://github.com/Automattic/wp-codebox/issues/1838). It compiles the current PHP 8.5 Asyncify Wasm asset for workerd, boots WordPress through Playground with the current SQLite integration release, executes PHP, and returns a Codebox runtime-command-result envelope containing the stable `wp-codebox/cloudflare-runtime-health/v1` health payload.
44

5-
The Worker owns Cloudflare transport and isolate lifecycle. Full WordPress initialization requires the paid-plan five-minute CPU allowance, declared as `limits.cpu_ms: 300000`; Cloudflare's fixed 128 MB isolate memory limit remains unchanged. This gate uses one Playground PHP instance per isolate; Durable Objects will serialize site mutation in a later gate. The response identifies the generic `wordpress-playground` backend and `wordpress` environment; callers do not receive Cloudflare binding or limit details. Runtime snapshots, restore, R2, serialization, and cold restoration are deferred to later gates.
5+
The Worker owns Cloudflare transport, PHP-WASM execution, and the caller-owned disposable SQLite cache. [MDI PR #126](https://github.com/Automattic/markdown-database-integration/pull/126), pinned at `94b9f875ffb8402d5e8eb726893a12324e20f45c`, supplies the constrained public primary runtime: normal MDI driver SQL writes are explicitly flushed to deterministic relative Markdown/JSON paths. R2 stores immutable canonical revisions and the current pointer; the Durable Object owns only the persisted lease, base-revision validation, and CAS pointer promotion. SQLite is never uploaded. This preserves cold reconstruction from canonical R2 files and concurrent mutation serialization without expanding MDI's storage-only boundary.
6+
7+
Existing evidence covers full WordPress initialization and canonical R2 revision behavior. This update changes the source relationship from ad hoc writes to MDI's public constrained runtime, adds source-level bundle and mutation guards, and supports local packaging verification. It does not claim a new remote deployment.
68

79
## Verification
810

Binary file not shown.
Binary file not shown.
Binary file not shown.

packages/runtime-cloudflare/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"type": "module",
66
"dependencies": {
77
"@automattic/wp-codebox-core": "file:../runtime-core",
8+
"@php-wasm/stream-compression": "^3.1.45",
89
"@php-wasm/universal": "3.1.45",
910
"@php-wasm/web-8-5": "3.1.45",
1011
"@wp-playground/wordpress": "3.1.45"

packages/runtime-cloudflare/src/php-wasm-universal.d.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
declare module "@php-wasm/universal" {
22
export class PHP {
33
constructor(runtimeId: number)
4-
run(request: { code: string }): Promise<{ text: string }>
4+
run(request: { code: string }): Promise<{ bytes: Uint8Array; text: string }>
5+
isDir(path: string): boolean
6+
listFiles(path: string): string[]
7+
mkdir(path: string): void
8+
readFileAsBuffer(path: string): Uint8Array
9+
writeFile(path: string, data: Uint8Array): void
10+
exit(code?: number): void
511
}
612

713
export function loadPHPRuntime(loader: {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module "*.sqlite" {
2+
const database: ArrayBuffer
3+
export default database
4+
}

packages/runtime-cloudflare/src/worker.ts

Lines changed: 630 additions & 8 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)