当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP realpath_cache_get()用法及代码示例


realpath_cache_get() 函数是 PHP 中的内置函数,用于检索真实路径缓存的当前内容。 PHP 使用真实路径缓存来存储将文件路径映射到文件系统上的真实或规范路径的结果。

用法:

realpath_cache_get(): array

Parameters: 该函数不接受任何参数。

返回值: realpath_cache_get()PHP 中的函数返回一个数组,其中包含有关真实路径缓存当前内容的信息。数组中的每个条目对应一个缓存的真实路径,并包含以下信息:

  • filename:用于生成缓存真实路径的路径。
  • realpath:文件系统上与缓存路径对应的真实或规范路径。
  • expires:缓存的真实路径将过期并从缓存中删除的时间戳。

示例 1:下面的程序演示了realpath_cache_get()函数。

PHP


<?php 
$cache = realpath_cache_get(); 
print_r($cache); 
?>

输出:

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
       )
)
 

示例 2:下面的程序演示了realpath_cache_get()函数。

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"; 
} 
?>

输出:

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
 

注意:输出是特定于系统的,并且根据系统的不同而有所不同。

参考:https://www.php.net/manual/en/function.realpath-cache-get.php



相关用法


注:本文由纯净天空筛选整理自neeraj3304大神的英文原创作品 PHP realpath_cache_get() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。