PHP Types Resources


A resource is a special type of variable that references an external resource, such as a file, socket, stream, document, or connection.

$file = fopen('/etc/passwd', 'r');

echo gettype($file);
# Out: resource

echo $file;
# Out: Resource id #2

There are different (sub-)types of resource. You can check the resource type using get_resource_type():

$file = fopen('/etc/passwd', 'r');
echo get_resource_type($file);
#Out: stream

$sock = fsockopen('', 80);
echo get_resource_type($sock);
#Out: stream

You can find a complete list of built-in resource types here.