PHP/resource: Difference between revisions
No edit summary |
No edit summary |
||
| Line 7: | Line 7: | ||
{| class=wikitable | {| class=wikitable | ||
! type || subtype || functions | ! type || subtype || functions | ||
{{!-!}} curl || cURL handle | {{!-!}} [[/curl/]] || cURL handle | ||
{{!-!}} process || || <code>[https://www.php.net/manual/en/function.proc-open.php proc_open()], [https://www.php.net/manual/en/function.proc-get-status.php proc_get_status()], [https://www.php.net/manual/en/function.proc-terminate.php proc_terminate()], [https://www.php.net/manual/en/function.proc-close.php proc_close()]</code> | {{!-!}} [[/process/]] || || <code>[https://www.php.net/manual/en/function.proc-open.php proc_open()], [https://www.php.net/manual/en/function.proc-get-status.php proc_get_status()], [https://www.php.net/manual/en/function.proc-terminate.php proc_terminate()], [https://www.php.net/manual/en/function.proc-close.php proc_close()]</code> | ||
{{!-!}} stream || dir handle | {{!-!}} [[/stream/]] || dir handle | ||
{{!-!}} stream || file handle | {{!-!}} [[/stream/]] || file handle | ||
{{!-!}} stream || process handle | {{!-!}} [[/stream/]] || process handle | ||
{{!-!}} socket || file handle | {{!-!}} [[/socket/]] || file handle | ||
{{!-!}} ssh2 session | {{!-!}} [[/ssh2/]] session | ||
{{!-!}} ssh2 listener | {{!-!}} [[/ssh2/]] listener | ||
{{!-!}} ssh2 SFTP | {{!-!}} [[/ssh2/]] SFTP | ||
{{!-!}} ssh2 publickey system | {{!-!}} [[/ssh2/]] publickey system | ||
|} | |} | ||
Source: [https://www.php.net/manual/en/resource.php List of Resource Types] | Source: [https://www.php.net/manual/en/resource.php List of Resource Types] | ||
Revision as of 19:46, 18 January 2026
About
In PHP, a "resource" value is an opaque internal pointer for handling certain types of I/O-ish operations.
Syntax
As of PHP 8.5, although "resource" is "soft-reserved and is used as a documentation pseudotype, there is no actual "resource" type; the only type which is currently known to be compatible with resource variables is "mixed". PHP currently interprets invocation of "resource" as a type as a reference to an unknown class named "Template:Fmt/arg\resource".
Types
There are many specialty resource-types defined by extensions, and a handful of more general types:
| type | subtype | functions |
|---|---|---|
| /curl/ | cURL handle | |
| /process/ | proc_open(), proc_get_status(), proc_terminate(), proc_close()
| |
| /stream/ | dir handle | |
| /stream/ | file handle | |
| /stream/ | process handle | |
| /socket/ | file handle | |
| /ssh2/ session | ||
| /ssh2/ listener | ||
| /ssh2/ SFTP | ||
| /ssh2/ publickey system |
Source: List of Resource Types
Advanced
New stream resource types can be defined in code with stream_wrapper_register().
Functions
These are just the general functions that apply to all resources; there are many others that do things with specific types of resources. In general, this is all not very well documented (there is plenty of documentation, but very little of it explains how things work).
get_resource_id()get_resource_type()is_resource()- If passed a resource variable,
get_debug_type()will indicate whether it is open or closed. (Surely there is some more rigorous way to get this information, however.)
