解码缓存url的多个选项

问题描述:

我有一个脚本需要从不同的缓存URL中提取数据。解码缓存url的多个选项

现在$ url ='http://example.com/search.php?user=abc&part='。$ part;

我需要的脚本的部分的下方修饰以搜索多个MD5加密的URL


$ URL = 'http://example.com/search.php?user=abc&part=' $部分。
$ url ='http://example.com/search.php?user=xyz&part='。$ part;
$ url ='http://example.com/search.php?user=123&part='。$ part;

如果返回的值超过1,则返回带有最新日期的值。

$ xid需要是$ url的当前设置

原始码。

function get_cache_file($url) { 
     $xid = md5($url); 

     $gendir = CACHE_ROOT . substr($xid, 0, 1) . '/'. substr($xid, 1, 2); 

     if(!is_dir($gendir)) { 
      mkdir($gendir, 0777, true); 
      } 

     return $gendir . '/' . $xid; 
    } 

找到了问题的答案。

function get_cache_file($part) 
{ 
    $users = array('user1', 'user2', 'user3'); 

    $file = ''; 
    $time = 0; 

    foreach ($users as $user) { 
     $url = 'http://example.com/search.php?user=' . $user . '&part=' . $part; 
     $xid = md5($url); 

     $gendir = CACHE_ROOT . substr($xid, 0, 1) . '/' . substr($xid, 1, 2); 

     if (is_dir($gendir) && is_file($gendir . '/' . $xid)) { 
      if ($time < filemtime($file)) { 
       $time = filemtime($file); 
       $file = $gendir . '/' . $xid; 
      } 
     } 
    }