[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details

PHP Directories and Files functions performance on a windows share

Asked by laurent_sicard in PHP for Windows, Samba File Sharing, Apache Web Server

Tags: php, cifs, smb, windows, linux, readdir, opendir, slow

Hello Experts,

Here is the situation...

1 - I have a folder (let's call it the root folder) containing all my mp3s on a Windows XP Pro SP3 (folders named by artists, then subfolders named by albums, then files). You can look at the attachement "diagram.jpg"
2 - An index.php file is located in this directory.
3 - This index.php is processed by an apache webserver (which of course has an alias configured to point to that directory)
4 - The index.php browse recursively the root folder with opendir, readdit and is_dir PHP functions. It diplays all the folders with links to listen to them, etc....

...and here is the problem:

When Apache is located on another Windows box (XP SP3 or Server 2003), the folder is accessed by Apache via a UNC path (\\192.168.5.10\MP3\) and the processing of the whole folder takes approx 30 seconds.

When Apache is located LOCALLY (XP SP3 then), the folder is accessed by Apache via a physisical path (F:\MP3\) and it takes 2 seconds to complete.

When Apache is located on a Linux Box (Ubuntu), the folder is accessed by Apache via a cifs mount (/mnt/mp3mntpoint/) and the processing of the whole folder is almost instant.


I was really puzzled by this siutation, the source server reamins the same (XP SP3 with all mp3s on it), the index.php is then strictly the same. But when being processed by a remote web server it is instant with Linux it takes soooo long with Windows (altough this is their prioritary protocol used between 2 windows boxes!!!). I am currently focusing my search on the readdir/opendir functions and the smb/cifs protocol.
When I network monitor the interface on the XP box containing the MP3s. I can see that there way more SMB traffic when the remote Windows access it than with Linux. I can attach the WireShark capture if you wish. You can reproduce this by using the greatly simplified php script attached (it simply recursively browse the folder).


INTRODUCTORY QUESTION:
Do you agree this is a readdir/opendir and/or cifs/smb protocol issue? At what level?
Is there a way to know what windows functions are called when using readdir?

MAIN QUESTION:
IS THERE A WAY TO HAVE THE WINDOWS REMOTE BOX, BE FASTER (maybe should I say less chatty when chatting with the MP3 box)?


Thanks in advance for your input.

Kind Regards,
Laurent
www.teltip.com



1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
<?php 
function getDirectory( $path = '.', $level = 0 ){
    $ignore = array( 'cgi-bin', '.', '..' );
    // Directories to ignore when listing output. Many hosts
    // will deny PHP access to the cgi-bin.
    $dh = @opendir( $path );
    // Open the directory to the handle $dh
  
    while( false !== ( $file = readdir( $dh ) ) ){
    // Loop through the directory
    
        if( !in_array( $file, $ignore ) ){
        // Check that this file is not to be ignored
            
            $spaces = str_repeat( '&nbsp;', ( $level * 4 ) );
            // Just to add spacing to the list, to better
            // show the directory tree.
            
            if( is_dir( "$path/$file" ) ){
            // Its a directory, so we need to keep reading down...
            
                echo "<strong>$spaces $file</strong><br />";
                getDirectory( "$path/$file", ($level+1) );
                // Re-call this same function but on a new directory.
                // this is what makes function recursive.
            
            } else {
            
                echo "$spaces $file<br />";
                // Just print out the filename
            
            }
        
        }
    
    }
    closedir( $dh );
    // Close the directory handle
}
getDirectory( "." ); 
?> 
Attachments:
 
Diagram
Diagram
 
[+][-]11/05/09 07:09 AM, ID: 25750237Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/09 02:05 PM, ID: 25754567Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625