NodePHP
Hierarchy
- BasePHP
- NodePHP
Index
Properties
Accessors
Methods
- [dispose]
- addEventListener
- chdir
- cli
- defineConstant
- dispatchEvent
- exit
- fileExists
- hotSwapPHPRuntime
- initializeRuntime
- internalUrlToPath
- isDir
- listFiles
- mkdir
- mkdirTree
- mount
- mv
- onMessage
- pathToInternalUrl
- readFileAsBuffer
- readFileAsText
- removeEventListener
- request
- rmdir
- run
- setPhpIniEntry
- setPhpIniPath
- setSapiName
- setSkipShebang
- setSpawnHandler
- unlink
- useHostFilesystem
- writeFile
- load
- loadRuntime
Properties
optionalrequestHandler
semaphore
Accessors
absoluteUrl
Returns string
documentRoot
Returns string
Methods
[dispose]
Returns void
addEventListener
Parameters
eventType: request.end | request.error | runtime.initialized | runtime.beforedestroy
listener: PHPEventListener
Returns void
chdir
Parameters
path: string
Returns void
cli
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
Parameters
key: string
value: null | string | number | boolean
Returns void
dispatchEvent
Type parameters
- Event: PHPEvent
Parameters
event: Event
Returns void
exit
Parameters
code: number = 0
Returns void
fileExists
Parameters
path: string
Returns boolean
hotSwapPHPRuntime
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
Parameters
runtimeId: number
Returns void
internalUrlToPath
Parameters
internalUrl: string
Returns string
isDir
Parameters
path: string
Returns boolean
listFiles
Parameters
path: string
options: ListFilesOptions = ...
Returns string[]
mkdir
Parameters
path: string
Returns void
mkdirTree
Parameters
path: string
Returns void
mount
Mounts a Node.js filesystem to a given path in the PHP filesystem.
Parameters
localPath: string | MountSettings
The path of a real local directory you want to mount.
virtualFSPath: string
Where to mount it in the virtual filesystem.
Returns void
mv
Parameters
fromPath: string
toPath: string
Returns void
onMessage
Parameters
listener: MessageListener
Returns Promise<void>
pathToInternalUrl
Parameters
path: string
Returns string
readFileAsBuffer
Parameters
path: string
Returns Uint8Array
readFileAsText
Parameters
path: string
Returns string
removeEventListener
Parameters
eventType: request.end | request.error | runtime.initialized | runtime.beforedestroy
listener: PHPEventListener
Returns void
request
Do not use. Use new PHPRequestHandler() instead.
Parameters
request: PHPRequest
Returns Promise<PHPResponse>
rmdir
Parameters
path: string
options: RmDirOptions = ...
Returns void
run
Parameters
request: PHPRunOptions
Returns Promise<PHPResponse>
setPhpIniEntry
Parameters
key: string
value: string
Returns void
setPhpIniPath
Parameters
path: string
Returns void
setSapiName
Parameters
newName: string
Returns Promise<void>
setSkipShebang
Parameters
shouldSkip: boolean
Returns void
setSpawnHandler
Parameters
handler: string | SpawnHandler
Returns Promise<void>
unlink
Parameters
path: string
Returns void
useHostFilesystem
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
Parameters
path: string
data: string | Uint8Array
Returns void
staticload
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
, andPHP.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
Does what load() does, but synchronously returns an object with the PHP instance and a promise that resolves when the PHP instance is ready.
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>
An exclusive lock that prevent multiple requests from running at the same time.