php8.5
Home/ Manual/ info / functions/ get_resources

get_resources

PHP function Edit on GitHub ✎

(PHP 7, PHP 8)

Returns active resources

Description

get_resources(string|null $type = null): array

Returns an array of all currently active resources, optionally filtered by resource type.

Note

This function is meant for debugging and testing purposes. It is not supposed to be used in production environments, especially not to access or even manipulate resources which are normally not accessible (e.g. the underlying stream resource of SplFileObject instances).

Parameters

type

If defined, this will cause get_resources() to only return resources of the given type. A list of resource types is available.

If the string Unknown is provided as the type, then only resources that are of an unknown type will be returned.

If omitted, all resources will be returned.

Return Values

Returns an array of currently active resources, indexed by resource number.

Changelog

VersionDescription
8.0.0type is nullable now.

Examples

Unfiltered get_resources()

php
<?php
$fp = tmpfile();
var_dump(get_resources());
?>

The above example will output something similar to:

output
array(1) {
  [1]=>
  resource(1) of type (stream)
}

Filtered get_resources()

php
<?php
$fp = tmpfile();
var_dump(get_resources('stream'));
var_dump(get_resources('curl'));
?>

The above example will output something similar to:

output
array(1) {
  [1]=>
  resource(1) of type (stream)
}
array(0) {
}

See Also

Source: reference/info/functions/get-resources.xml · from the official PHP manual (php/doc-en)