PHP Version
4+
/* File resource */
$file = fopen('test.txt', 'w');
var_dump(is_resource($file)); // bool(true)

/* Database connection resource */
$connection = mysqli_connect("localhost", "username", "password", "database");
var_dump(is_resource($connection)); // bool(true)

/* Image resource (when using the GD library for image creation) */
$image = imagecreate(100, 100);
var_dump(is_resource($image)); // bool(true)

/* Network connection resource */
$network = fsockopen("example.com", 80);
var_dump(is_resource($network)); // bool(true)
is_resource(mixed $value): bool
/* Opening a file */
$fp = fopen('test.txt', 'w');
var_dump(is_resource($fp)); // bool(true)

/* Closing the file handle */
fclose($fp); // The resource is now closed
var_dump(is_resource($fp)); // bool(false)
/* Opening a file */
$fp = fopen('test.txt', 'w');

/* Closing the file handle */
fclose($fp);

echo gettype($fp); // 'resource (closed)'
/* Opening a file */
$file = fopen('test.txt', 'r');

if (is_resource($file)) {
	// File processing code
} else {
	echo 'The file is invalid.';
}

/* Closing the file handle */
fclose($file);
/* Creating an XML parser */
$xml_parser = xml_parser_create();

if (is_resource($xml_parser)) {
    // Parsing can be performed only if the XML parser is a valid resource
    xml_parse($xml_parser, "<tag>content</tag>", true);
    // Process results
    xml_parser_free($xml_parser);
} else {
    echo 'The XML parser resource is invalid.';
}