Skip to main content

NodePHP

Hierarchy

  • BasePHP
    • NodePHP

Index

Properties

optionalrequestHandler

requestHandler?: PHPRequestHandler<any>

semaphore

semaphore: default

An exclusive lock that prevent multiple requests from running at the same time.

Accessors

absoluteUrl

  • get absoluteUrl(): string
  • @inheritDoc

    Returns string

documentRoot

  • get documentRoot(): string
  • @inheritDoc

    Returns string

Methods

[dispose]

  • [dispose](): void
  • Returns void

addEventListener

  • addEventListener(eventType: request.end | request.error | runtime.initialized | runtime.beforedestroy, listener: PHPEventListener): void
  • Parameters

    • eventType: request.end | request.error | runtime.initialized | runtime.beforedestroy
    • listener: PHPEventListener

    Returns void

chdir

  • chdir(path: string): void
  • @inheritDoc

    Parameters

    • path: string

    Returns void

cli

  • cli(argv: string[]): Promise<number>
  • Starts a PHP CLI session with given arguments.

    This method can only be used when PHP was compiled with the CLI SAPI and it cannot be used in conjunction with run().

    Once this method finishes running, the PHP instance is no longer usable and should be discarded. This is because PHP internally cleans up all the resources and calls exit().


    Parameters

    • argv: string[]

      The arguments to pass to the CLI.

    Returns Promise<number>

    The exit code of the CLI session.

defineConstant

  • defineConstant(key: string, value: null | string | number | boolean): void
  • Parameters

    • key: string
    • value: null | string | number | boolean

    Returns void

dispatchEvent

  • dispatchEvent<Event>(event: Event): void
  • Type parameters

    • Event: PHPEvent

    Parameters

    • event: Event

    Returns void

exit

  • exit(code?: number): void
  • Parameters

    • code: number = 0

    Returns void

fileExists

  • fileExists(path: string): boolean
  • @inheritDoc

    Parameters

    • path: string

    Returns boolean

hotSwapPHPRuntime

  • hotSwapPHPRuntime(runtime: number, cwd?: string): void
  • Hot-swaps the PHP runtime for a new one without interrupting the operations of this PHP instance.


    Parameters

    • runtime: number
    • optionalcwd: string

    Returns void

initializeRuntime

  • initializeRuntime(runtimeId: number): void
  • Parameters

    • runtimeId: number

    Returns void

internalUrlToPath

  • internalUrlToPath(internalUrl: string): string
  • @inheritDoc

    Parameters

    • internalUrl: string

    Returns string

isDir

  • isDir(path: string): boolean
  • @inheritDoc

    Parameters

    • path: string

    Returns boolean

listFiles

  • listFiles(path: string, options?: ListFilesOptions): string[]
  • @inheritDoc

    Parameters

    • path: string
    • options: ListFilesOptions = ...

    Returns string[]

mkdir

  • mkdir(path: string): void
  • @inheritDoc

    Parameters

    • path: string

    Returns void

mkdirTree

  • mkdirTree(path: string): void
  • @inheritDoc

    Parameters

    • path: string

    Returns void

mount

  • mount(localPath: string | MountSettings, virtualFSPath: string): void

mv

  • mv(fromPath: string, toPath: string): void
  • @inheritDoc

    Parameters

    • fromPath: string
    • toPath: string

    Returns void

onMessage

  • onMessage(listener: MessageListener): Promise<void>
  • @inheritDoc

    Parameters

    • listener: MessageListener

    Returns Promise<void>

pathToInternalUrl

  • pathToInternalUrl(path: string): string
  • @inheritDoc

    Parameters

    • path: string

    Returns string

readFileAsBuffer

  • readFileAsBuffer(path: string): Uint8Array
  • @inheritDoc

    Parameters

    • path: string

    Returns Uint8Array

readFileAsText

  • readFileAsText(path: string): string
  • @inheritDoc

    Parameters

    • path: string

    Returns string

removeEventListener

  • removeEventListener(eventType: request.end | request.error | runtime.initialized | runtime.beforedestroy, listener: PHPEventListener): void
  • Parameters

    • eventType: request.end | request.error | runtime.initialized | runtime.beforedestroy
    • listener: PHPEventListener

    Returns void

request

  • request(request: PHPRequest): Promise<PHPResponse>
  • Do not use. Use new PHPRequestHandler() instead.

    @deprecated

    Parameters

    • request: PHPRequest

    Returns Promise<PHPResponse>

rmdir

  • rmdir(path: string, options?: RmDirOptions): void
  • @inheritDoc

    Parameters

    • path: string
    • options: RmDirOptions = ...

    Returns void

run

  • run(request: PHPRunOptions): Promise<PHPResponse>
  • @inheritDoc

    Parameters

    • request: PHPRunOptions

    Returns Promise<PHPResponse>

setPhpIniEntry

  • setPhpIniEntry(key: string, value: string): void
  • @inheritDoc

    Parameters

    • key: string
    • value: string

    Returns void

setPhpIniPath

  • setPhpIniPath(path: string): void
  • @inheritDoc

    Parameters

    • path: string

    Returns void

setSapiName

  • setSapiName(newName: string): Promise<void>
  • @inheritDoc

    Parameters

    • newName: string

    Returns Promise<void>

setSkipShebang

  • setSkipShebang(shouldSkip: boolean): void
  • Parameters

    • shouldSkip: boolean

    Returns void

setSpawnHandler

  • setSpawnHandler(handler: string | SpawnHandler): Promise<void>
  • @inheritDoc

    Parameters

    • handler: string | SpawnHandler

    Returns Promise<void>

unlink

  • unlink(path: string): void
  • @inheritDoc

    Parameters

    • path: string

    Returns void

useHostFilesystem

  • useHostFilesystem(): void
  • Enables host filesystem usage by mounting root directories (e.g. /, /home, /var) into the in-memory virtual filesystem used by this PHP instance, and setting the current working directory to one used by the current node.js process.


    Returns void

writeFile

  • writeFile(path: string, data: string | Uint8Array): void
  • @inheritDoc

    Parameters

    • path: string
    • data: string | Uint8Array

    Returns void

staticload

  • load(phpVersion: 8.3 | 8.2 | 8.1 | 8.0 | 7.4 | 7.3 | 7.2 | 7.1 | 7.0, options?: PHPLoaderOptions): Promise<NodePHP>
  • Creates a new PHP instance.

    Dynamically imports the PHP module, initializes the runtime, and sets up networking. It’s a shorthand for the lower-level functions like getPHPLoaderModule, loadPHPRuntime, and PHP.initializeRuntime


    Parameters

    • phpVersion: 8.3 | 8.2 | 8.1 | 8.0 | 7.4 | 7.3 | 7.2 | 7.1 | 7.0

      The PHP Version to load

    • options: PHPLoaderOptions = {}

      The options to use when loading PHP

    Returns Promise<NodePHP>

    A new PHP instance

staticloadRuntime

  • loadRuntime(phpVersion: 8.3 | 8.2 | 8.1 | 8.0 | 7.4 | 7.3 | 7.2 | 7.1 | 7.0, options?: PHPLoaderOptions): Promise<number>
  • Does what load() does, but synchronously returns an object with the PHP instance and a promise that resolves when the PHP instance is ready.

    @see

    load


    Parameters

    • phpVersion: 8.3 | 8.2 | 8.1 | 8.0 | 7.4 | 7.3 | 7.2 | 7.1 | 7.0
    • options: PHPLoaderOptions = {}

    Returns Promise<number>