Responsive Filemanager Showing Blank Screen or Errors

February 4th, 2014 - Posted by Steve Marks to Javascript / jQuery, PHP, Server Management, Software, Web Development.

I recently upgraded to version 4 of TinyMCE and needed a file manager that worked with this new version so that the user could upload and insert files into the WYSIWYG.

Fortunately I came across an excellent file manager called ‘Responsive filemanager‘ which was relatively easy to get setup and working (ie. it took less than 30 minutes):

Responsive Filemanager

The Problem

A weird scenario began to arise after using it for a few weeks whereby, when opening the file manager from within TinyMCE, it would simply hang. After a minute or two it would either present a blank white screen, or give me a ‘500 Internal Server Error‘ message.

My first point of call with anything like this was to check the server error logs. I quickly found the culprit when I saw this:

mod_fcgid: read data timeout in 45 seconds

45 seconds? That’s quite a long time! A quick Google for the solution presented people saying to simply extend this timeout limit. I would expect the filemanager to load in a few seconds, let alone 45 seconds, so increasing this time limit didn’t feel right.

I set about to find out the cause of the delay and would go from there.

Finding The Cause

The error log was claiming that the error was occurring in the file ‘/filemanager/includes/utils.php‘ on line 68. This turned out to be a function called foldersize() which calculated the total size of all the folders being shown.

This got me thinking; what if one of the folders in the uploads directory contained a lot of files? If it’s looping through each file to get the total folder size this could take a while and definitely cause a timeout.

It turns out that I was absolutely right. I had a subdirectory in my uploads folder which contained thousands upon thousands of files. This was only going to get bigger too so the delay would only get worse over time.

The Solution(s)

To deal with this particular issue I came up with three possible solutions which I explain below:

1. Increase the timeout
The first option was to increase the timeout setting so that eventually the page would load. This can be done in Apache in the /etc/httpd/conf.d/fcgid.conf file. Simply increase the ‘FcgidIOTimeout’ setting to a number (in seconds) that you feel will be long enough.

Note: You’ll probably have to increase the ‘max_execution_timePHP.ini directive too if you opt for this solution.

Note 2: You’ll have to restart Apache if you change the above setting.

2. Move the large subdirectory out of the uploads folder
In the ‘/filemanager/config/config.php‘ file you can set the path to the uploads directory via the $upload_dir variable. In my scenario I could have moved the large directory causing issues out of here.

Unfortunately these directory structures were deep rooted into the site and this would have caused massive headache.

3. Explicitly ignore the troublesome large subdirectory
The third, albeit a bit hacky, solution I came up with was to ignore this large subdirectory within the function that calculated the folder size.

Let’s imagine that the subdirectory in question was called ‘my-files’, I could modify the function in utils.php to be as follows:

function foldersize($path) {
    $total_size = 0;
    $files = scandir($path);
    $cleanPath = rtrim($path, '/'). '/';
    // Only include files that aren't in the large subdirectory
    if ( strpos($path, "/my-files/") === FALSE )
        foreach($files as $t) {
            if ($t<>"." && $t<>"..") {
                $currentFile = $cleanPath . $t;
                if (is_dir($currentFile)) {
                    $size = foldersize($currentFile);
                    $total_size += $size;
                else {
                    $size = filesize($currentFile);
                    $total_size += $size;


    return $total_size;

In the interests of time and effort, this is actually the option that I opted for. The filemanager still works exactly as it did before, is much quicker, and I now no longer get error messages or blank screens.

In fact, I can’t tell any difference or disadvantages so I’ll stick with this solution for now. I think if I had more time I’d restructure my folders but I’ll maybe save this for a rainy day.

This entry was posted on Tuesday, February 4th, 2014 at 7:50 pm by +Steve Marks and is filed under Javascript / jQuery, PHP, Server Management, Software, Web Development. You can follow any responses to this entry through the RSS 2.0 feed.

Fear not, we won't publish this

Comments (0)

No comments have been left yet. Be the first