What is fstat() function in PHP?

The fstat() function returns information about an open file. This function returns an array of information containing the following data:

  • [0] or [dev] - Device number
  • [1] or [ino] - Inode number
  • [2] or [mode] - Inode protection mode
  • [3] or [nlink] - Number of links
  • [4] or [uid] - User ID of owner
  • [5] or [gid] - Group ID of owner
  • [6] or [rdev] - Inode device type
  • [7] or [size] - Size in bytes
  • [8] or [atime] - Last access (as Unix timestamp)
  • [9] or [mtime] - Last modified (as Unix timestamp)
  • [10] or [ctime] - Last inode change (as Unix timestamp)
  • [11] or [blksize] - Blocksize of filesystem IO (if supported)
  • [12] or [blocks] - Number of blocks allocated

In order to use this function, it is important for the file to be open.

Syntax

fstat(resource $stream): array|false

Parameters and return value

stream: A file stream associated with an open file for which the information is required.

This function returns an array containing the information. If the function does not execute properly, it returns false.

Code

Let’s have a look at the usage of this function. In this example, we create a file hello.txt, pass it to the function fstat(), and look at the output from the function. Keep in mind that we must open the file in order to use this method.

main.php
hello.txt
<?php
$file = fopen("hello.txt","r");
print_r(fstat($file));
fclose($file);
?>
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved