Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8977733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:26:24+00:00 2026-06-15T19:26:24+00:00

Possible Duplicate: Caching readdir() I have my site set up so that I have

  • 0

Possible Duplicate:
Caching readdir()

I have my site set up so that I have clean URLs and the files themselves are in various levels of folders. To manage it, I have the following script to direct my include farther down in the page.

    function listFolderFiles($dir,$exclude){
    global $flist;
    $ffs = scandir($dir); 
    foreach($ffs as $ff)
    { 
        if(is_array($exclude) and !in_array($ff,$exclude))
        { 
            if($ff != '.' && $ff != '..')
            { 
                if(!is_dir($dir.'/'.$ff))
                {       
            }
            if(is_dir($dir.'/'.$ff)) 
                {
                listFolderFiles($dir.'/'.$ff,$exclude);
            } 
            if((is_dir($dir.'/'.$ff)) != 1 && strtolower(substr($ff, strrpos($ff, '.') + 1)) == 'php')
                {
                    $name = basename($ff, ".php");
                    $flist[] .= $name;                  
                }
            }
        } 
    } 
}
listFolderFiles('content/',array('filelist.php')); 
$removing = array('_en','_es');
$pages = str_replace($removing, "", $flist);
unset($dir, $exclude, $flist);
listFolderFiles('content/Beginner/',array('filelist.php')); 
$removing = array('_en','_es');
$beginner = str_replace($removing, "", $flist);
unset($dir, $exclude, $flist);
listFolderFiles('content/Intermediate/',array('filelist.php', $beginner));
$removingi = array('_en','_es');
$intermediate = str_replace($removingi, "", $flist);
unset($dir, $exclude, $flist);
listFolderFiles('content/Advanced/',array('filelist.php', $beginner));
$removinga = array('_en','_es');
$advanced = str_replace($removinga, "", $flist);

Is there a faster way to execute this code, as it is currently used on every pageload, and I only need to update it when I add a new file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:26:25+00:00Added an answer on June 15, 2026 at 7:26 pm

    Aside from algorithmic improvements, this is a great candidate for caching. It looks like it could be as simple as serializing the array and dropping that into a file. Then you can decide what your expiration policy is. Pseudo code:

    if(!file_exists(CACHE_NAME) || dir_cache_expired(CACHE_NAME)) {
      // ... code to build $dirlist
      file_put_contents(CACHE_NAME, serialize($dirlist));
    } else {
      $dirlist = unserialize(file_get_contents(CACHE_NAME));
    }
    

    This way you can always trigger a rebuild of the cache by simply deleting the cache file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Caching in asp.net-mvc i have an asp.net-mvc site and i am running
Possible Duplicate: caching JavaScript files I'm using JQuery 1.7.2 into JSF page. I call
Possible Duplicate: Is Safari on iOS 6 caching $.ajax results? I have been having
Possible Duplicate: My HTML5 Application Cache Manifest is caching everything I have made an
Possible Duplicate: Floating point division vs floating point multiplication recently, i have written a
Possible Duplicate: How can a Java program use files inside the .jar for read
Possible Duplicate: Prevent caching of AJAX call I'm using jQuery to read a tiny
Possible Duplicate: HTML 5 offline caching I'm coming from a desktop app world, but
Possible Duplicate: New Integer vs valueOf I read at few place that Integer.valueOf is
Possible Duplicate: Size-limited queue that holds last N elements in Java Java - Ring

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.