The realpath_cache_get() function is an inbuilt function in PHP that retrieves the current contents of the realpath cache. The realpath cache is used by PHP to store the results of mapping file paths to their real or canonical paths on the filesystem.
Syntax:
realpath_cache_get(): array
Parameters: This function does not accept any parameter.
Return Values: The realpath_cache_get() function in PHP returns an array containing information about the current contents of the realpath cache. Each entry in the array corresponds to a cached realpath and includes the following information:
- filename: The path that was used to generate the cached realpath.
- realpath: The real or canonical path on the filesystem that corresponds to the cached path.
- expires: The timestamp at which the cached realpath will expire and be removed from the cache.
Example 1: The following program demonstrates the realpath_cache_get() function.
PHP
<?php $cache = realpath_cache_get(); print_r( $cache ); ?> |
Output:
Array ( [/home/dachman/Desktop] => Array ( [key] => 9.8987350635605E+18 [is_dir] => 1 [realpath] => /home/dachman/Desktop [expires] => 1680790990 ) [/home/dachman/Desktop/Articles/GFG/Method/index.php] => Array ( [key] => 1.1713322467E+19 [is_dir] => [realpath] => /home/dachman/Desktop/Articles/GFG/Method/index.php [expires] => 1680790990 ) [/home] => Array ( [key] => 4353355791257440477 [is_dir] => 1 [realpath] => /home [expires] => 1680790990 ) [/home/dachman/Desktop/Articles/GFG] => Array ( [key] => 1.7522950215249E+19 [is_dir] => 1 [realpath] => /home/dachman/Desktop/Articles/GFG [expires] => 1680790990 ) [/home/dachman/Desktop/Articles] => Array ( [key] => 1.4472601227808E+19 [is_dir] => 1 [realpath] => /home/dachman/Desktop/Articles [expires] => 1680790990 ) [/home/dachman/Desktop/Articles/GFG/Method] => Array ( [key] => 1554988915540397794 [is_dir] => 1 [realpath] => /home/dachman/Desktop/Articles/GFG/Method [expires] => 1680790990 ) [/home/dachman] => Array ( [key] => 1.4619779138232E+19 [is_dir] => 1 [realpath] => /home/dachman [expires] => 1680790990 ) )
Example 2: The following program demonstrates the realpath_cache_get() function.
PHP
<?php $cache = realpath_cache_get(); foreach ( $cache as $path => $info ) { echo "Path: $path\n" ; echo "Realpath: {$info[" realpath "]}\n" ; echo "Expires: " . date ( "Y-m-d H:i:s" , $info [ "expires" ]) . "\n\n" ; } ?> |
Output:
Path: /home/dachman/Desktop Realpath: /home/dachman/Desktop Expires: 2023-04-06 14:27:00 Path: /home/dachman/Desktop/Articles/GFG/Method/index.php Realpath: /home/dachman/Desktop/Articles/GFG/Method/index.php Expires: 2023-04-06 14:27:00 Path: /home Realpath: /home Expires: 2023-04-06 14:27:00 Path: /home/dachman/Desktop/Articles/GFG Realpath: /home/dachman/Desktop/Articles/GFG Expires: 2023-04-06 14:27:00 Path: /home/dachman/Desktop/Articles Realpath: /home/dachman/Desktop/Articles Expires: 2023-04-06 14:27:00 Path: /home/dachman/Desktop/Articles/GFG/Method Realpath: /home/dachman/Desktop/Articles/GFG/Method Expires: 2023-04-06 14:27:00 Path: /home/dachman Realpath: /home/dachman Expires: 2023-04-06 14:27:00
Note: Output is system-specific & will be different according to the system.
Reference: https://www.php.net/manual/en/function.realpath-cache-get.php