當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。