@php-wasm/universal 2.0.14 → 2.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,9 @@
1
1
  import type { EmscriptenDownloadMonitor } from '@php-wasm/progress';
2
+ import type { ListFilesOptions, RmDirOptions } from './fs-helpers';
2
3
  import type { PHP } from './php';
3
4
  import type { PHPRequestHandler } from './php-request-handler';
4
- import type { PHPResponse } from './php-response';
5
- import type { PHPRequest, PHPRunOptions, MessageListener, PHPEvent, PHPEventListener } from './universal-php';
6
- import type { RmDirOptions, ListFilesOptions } from './fs-helpers';
5
+ import type { PHPResponse, StreamedPHPResponse } from './php-response';
6
+ import type { MessageListener, PHPEvent, PHPEventListener, PHPRequest, PHPRunOptions } from './universal-php';
7
7
  export type LimitedPHPApi = Pick<PHP, 'request' | 'defineConstant' | 'addEventListener' | 'removeEventListener' | 'mkdir' | 'mkdirTree' | 'readFileAsText' | 'readFileAsBuffer' | 'writeFile' | 'unlink' | 'mv' | 'rmdir' | 'listFiles' | 'isDir' | 'fileExists' | 'chdir' | 'run' | 'onMessage'> & {
8
8
  documentRoot: PHP['documentRoot'];
9
9
  absoluteUrl: PHP['absoluteUrl'];
@@ -52,6 +52,10 @@ export declare class PHPWorker implements LimitedPHPApi, AsyncDisposable {
52
52
  request(request: PHPRequest): Promise<PHPResponse>;
53
53
  /** @inheritDoc @php-wasm/universal!/PHP.run */
54
54
  run(request: PHPRunOptions): Promise<PHPResponse>;
55
+ /** @inheritDoc @php-wasm/universal!/PHP.cli */
56
+ cli(argv: string[], options?: {
57
+ env?: Record<string, string>;
58
+ }): Promise<StreamedPHPResponse>;
55
59
  /** @inheritDoc @php-wasm/universal!/PHP.chdir */
56
60
  chdir(path: string): void;
57
61
  /** @inheritDoc @php-wasm/universal!/PHP.setSapiName */
package/lib/php.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { PHPResponse, StreamedPHPResponse } from './php-response';
2
- import type { PHPRuntimeId } from './load-php-runtime';
3
- import type { MessageListener, PHPRequest, PHPRequestHeaders, PHPRunOptions, SpawnHandler, PHPEventListener, PHPEvent } from './universal-php';
4
- import type { RmDirOptions, ListFilesOptions } from './fs-helpers';
5
1
  import { Semaphore } from '@php-wasm/util';
6
- import type { PHPRequestHandler } from './php-request-handler';
7
2
  import type { Emscripten } from './emscripten-types';
3
+ import type { ListFilesOptions, RmDirOptions } from './fs-helpers';
4
+ import type { PHPRuntimeId } from './load-php-runtime';
5
+ import type { PHPRequestHandler } from './php-request-handler';
6
+ import { PHPResponse, StreamedPHPResponse } from './php-response';
7
+ import type { MessageListener, PHPEvent, PHPEventListener, PHPRequest, PHPRequestHeaders, PHPRunOptions, SpawnHandler } from './universal-php';
8
8
  export declare const __private__dont__use: unique symbol;
9
9
  type ErrorSource = 'request' | 'php-wasm';
10
10
  export declare class PHPExecutionFailureError extends Error {
@@ -28,8 +28,6 @@ export declare class PHP implements Disposable {
28
28
  #private;
29
29
  protected [__private__dont__use]: any;
30
30
  requestHandler?: PHPRequestHandler;
31
- private cliCalled;
32
- private runStreamCalled;
33
31
  /**
34
32
  * An exclusive lock that prevent multiple requests from running at
35
33
  * the same time.
@@ -412,6 +410,16 @@ export declare class PHP implements Disposable {
412
410
  * @returns True if the file exists, false otherwise.
413
411
  */
414
412
  fileExists(path: string): boolean;
413
+ /**
414
+ * Enables inline PHP runtime rotation after a certain number of requests
415
+ * or an internal crash.
416
+ */
417
+ enableRuntimeRotation(options: {
418
+ recreateRuntime: () => Promise<number> | number;
419
+ maxRequests?: number;
420
+ cwd?: string;
421
+ }): void;
422
+ private rotateRuntime;
415
423
  /**
416
424
  * Hot-swaps the PHP runtime for a new one without
417
425
  * interrupting the operations of this PHP instance.
@@ -1,24 +1,14 @@
1
1
  import type { PHP } from './php';
2
2
  export interface RotateOptions {
3
3
  php: PHP;
4
- cwd: string;
4
+ cwd?: string;
5
5
  recreateRuntime: () => Promise<number> | number;
6
- maxRequests: number;
6
+ maxRequests?: number;
7
7
  }
8
8
  /**
9
- * Listens to PHP events and swaps the internal PHP Runtime for a fresh one
10
- * after a certain number of run() calls (which are responsible for handling
11
- * HTTP requests).
9
+ * Configures inline runtime rotation on the provided PHP instance.
10
+ * Returns a cleanup function that disables rotation.
12
11
  *
13
- * Why? Because PHP and PHP extension have a memory leak. Each request leaves
14
- * the memory a bit more fragmented and with a bit less available space than
15
- * before. Eventually, new allocations start failing.
16
- *
17
- * Rotating the PHP instance may seem like a workaround, but it's actually
18
- * what PHP-FPM does natively:
19
- *
20
- * https://www.php.net/manual/en/install.fpm.configuration.php#pm.max-tasks
21
- *
22
- * @return cleanup function to restore
12
+ * @deprecated Use `php.enableRuntimeRotation()` instead.
23
13
  */
24
- export declare function rotatePHPRuntime({ php, cwd, recreateRuntime, maxRequests, }: RotateOptions): () => void;
14
+ export declare function rotatePHPRuntime({ php, cwd, recreateRuntime, maxRequests, }: RotateOptions): void;
@@ -21,17 +21,17 @@ export interface PHPRuntimeInitializedEvent {
21
21
  type: 'runtime.initialized';
22
22
  }
23
23
  /**
24
- * Represents a PHP runtime destruction event.
24
+ * Emitted before the exit() method of the PHP Emscripten runtime is called.
25
25
  */
26
- export interface PHPRuntimeBeforeDestroyEvent {
27
- type: 'runtime.beforedestroy';
26
+ export interface PHPRuntimeBeforeExitEvent {
27
+ type: 'runtime.beforeExit';
28
28
  }
29
29
  /**
30
30
  * Represents an event related to the PHP instance.
31
31
  * This is intentionally not an extension of CustomEvent
32
32
  * to make it isomorphic between different JavaScript runtimes.
33
33
  */
34
- export type PHPEvent = PHPRequestEndEvent | PHPRequestErrorEvent | PHPRuntimeInitializedEvent | PHPRuntimeBeforeDestroyEvent;
34
+ export type PHPEvent = PHPRequestEndEvent | PHPRequestErrorEvent | PHPRuntimeInitializedEvent | PHPRuntimeBeforeExitEvent;
35
35
  /**
36
36
  * A callback function that handles PHP events.
37
37
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/universal",
3
- "version": "2.0.14",
3
+ "version": "2.0.16",
4
4
  "description": "PHP.wasm – emscripten bindings for PHP",
5
5
  "repository": {
6
6
  "type": "git",
@@ -37,18 +37,18 @@
37
37
  "module": "./index.js",
38
38
  "types": "index.d.ts",
39
39
  "license": "GPL-2.0-or-later",
40
- "gitHead": "47972f56affb733e7a3b8734ed29229a00364ced",
40
+ "gitHead": "3587b829420250e2de23d2643151da75c0ccdbec",
41
41
  "engines": {
42
42
  "node": ">=20.18.3",
43
43
  "npm": ">=10.1.0"
44
44
  },
45
45
  "dependencies": {
46
46
  "ini": "4.1.2",
47
- "@php-wasm/node-polyfills": "2.0.14",
48
- "@php-wasm/logger": "2.0.14",
49
- "@php-wasm/util": "2.0.14",
50
- "@php-wasm/stream-compression": "2.0.14",
51
- "@php-wasm/progress": "2.0.14"
47
+ "@php-wasm/node-polyfills": "2.0.16",
48
+ "@php-wasm/logger": "2.0.16",
49
+ "@php-wasm/util": "2.0.16",
50
+ "@php-wasm/stream-compression": "2.0.16",
51
+ "@php-wasm/progress": "2.0.16"
52
52
  },
53
53
  "overrides": {
54
54
  "rollup": "^4.34.6",