PHP Web Host - Quality Web Hosting For All PHP Applications Free RavenNuke(tm) Add Ons
  Login or Register
 • Home • Downloads • Your Account • Forums • 

View next topic
View previous topic


Google
 
Web RavenPHPScripts (This Site)
Post new topic   Reply to topic
Author Message
testy1
Involved
Involved


Joined: Apr 06, 2008
Posts: 483

PostPosted: Tue Mar 31, 2009 1:28 am Reply with quote Back to top

Be good if someone else could verify this but after changing the following code, The modules block picked up nearly a second

Original:
Code:

/* If the module doesn't exist, it will be removed from the database automatically */
$result2 = $db->sql_query('SELECT title FROM ' . $prefix . '_modules');
while ($row2 = $db->sql_fetchrow($result2)) {
    $title = stripslashes($row2['title']);
    $a = 0;
    $handle=opendir('modules');
    while ($file = readdir($handle)) {
        if ($file == $title) {
            $a = 1;
        }
    }
    closedir($handle);
    if ($a == 0) {
        $db->sql_query('DELETE FROM '.$prefix.'_modules WHERE title=\''.$title.'\'');
    }
}


Modified:
Code:

/* If the module doesn't exist, it will be removed from the database automatically */
$result2 = $db->sql_query('SELECT title FROM ' . $prefix . '_modules');
while ($row2 = $db->sql_fetchrow($result2)) {
    $title = stripslashes($row2['title']);
    $a = 0;
    $handle=opendir('modules');
    while ($file = readdir($handle)) {
      if (is_dir($file) && $file !== '.' || $file !== '..' ) {
        if ($file == $title) {
            $a = 1;
        }
      }
    }
    closedir($handle);
    if ($a == 0) {
        $db->sql_query('DELETE FROM '.$prefix.'_modules WHERE title=\''.$title.'\'');
    }
}


EDIT: It has added another cost for is_dir() Sad


Last edited by testy1 on Wed Apr 01, 2009 5:32 pm; edited 1 time in total
View user's profile Send private message
fkelly
Moderator


Joined: Aug 30, 2005
Posts: 3186
Location: near Albany NY

PostPosted: Tue Mar 31, 2009 7:55 am Reply with quote Back to top

How are you measuring when you say you picked up a second? Intuitively I don't see where adding another layer of tests (the if is_dir statement) is going to be more efficient but of course the poof is in the prudding.
View user's profile Send private message Visit poster's website
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 16987
Location: Kansas

PostPosted: Tue Mar 31, 2009 3:43 pm Reply with quote Back to top

It really says while ($file = readdir($handle)) { ? That will always resolve to TRUE!

Correction: See the posts on down the way to get the entire resolution.

Instead of reading while ($file = readdir($handle)) { or while ($file == readdir($handle)) { it should read while (false !== ($file = readdir($handle))) { . It is actually an assignment and not a logical comparison.


Last edited by Raven on Thu Apr 02, 2009 11:22 pm; edited 1 time in total
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
testy1
Involved
Involved


Joined: Apr 06, 2008
Posts: 483

PostPosted: Wed Apr 01, 2009 12:46 am Reply with quote Back to top

yes I realized that it dropped a second or .8 of a second but is_dir incurred a cost of 2.8 ROTFL

I was so excited I just posted lol
View user's profile Send private message
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 16987
Location: Kansas

PostPosted: Wed Apr 01, 2009 10:12 am Reply with quote Back to top

We need to enter a Mantis issue on the logic error - = vs ==. You can't just change it because I tried that yesterday and that shut down all my modules to inactive so that logic block needs to be reworked.
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
Guardian2003
Site Admin


Joined: Aug 28, 2003
Posts: 6373
Location: Vsetin, Czech Republic

PostPosted: Wed Apr 01, 2009 10:23 am Reply with quote Back to top

Hmm, I don't even see the need for half of that stuff in the modules 'block'.
Access permissions are updated through admin functions so all the block needs to do is read from the DB once, how many modules are available.
I don't see the need for reading the DIR at all.
View user's profile Send private message Send e-mail Visit poster's website
fkelly
Moderator


Joined: Aug 30, 2005
Posts: 3186
Location: near Albany NY

PostPosted: Wed Apr 01, 2009 11:26 am Reply with quote Back to top

Guardian ... I think the logic may have been: what if someone goes into the file system and deletes /modules/my_module ... I mean the whole directory. The MYSQL table for modules would still have a record for my_module. So, we want to delete that record before the system tries to access the module file and creates an error.

Granted anyone with file system access should know enough to use Modules administration first and delete the module there before removing it from the file system but I'm not sure that always happens that way. I'm not sure this function needs to be run on every page load for every user but that's another matter.
View user's profile Send private message Visit poster's website
testy1
Involved
Involved


Joined: Apr 06, 2008
Posts: 483

PostPosted: Wed Apr 01, 2009 4:48 pm Reply with quote Back to top

Just as a quick test I did a complete fresh install and did a debug run with the following settings;


  • Not logged in as admin
  • Not logged in as a user (In other words I was just a guest)
  • Each test was run using ctr-F5 in firefox which is suppoose to clear the cache
  • Each test was run on the home page (index.php)
  • I ran each test 10 times and calculated the average
  • My wife over looked the whole procedure because she thinks she knows everything (I haven't got the heart to tell her otherwise Razz)


1. With the above in mind and all blocks active
189 functions called in an Average of 330 milliseconds
Actual cachefile size: 407KB

2. With the above in mind and all blocks active except the modules block
184 functions called in an Average of 263 milliseconds
Actual cachefile size: 271KB

It does not look like much, but it is actually a 79% gain.

anyway take it as you will.
View user's profile Send private message
fkelly
Moderator


Joined: Aug 30, 2005
Posts: 3186
Location: near Albany NY

PostPosted: Wed Apr 01, 2009 5:54 pm Reply with quote Back to top

This just goes to show how complex and difficult and subject to interpretation performance measurement can be. You could probably find some other block to deactivate that would yield an even greater performance gain. And your last post really doesn't address the proposed changes you made in your first post about the modules block and alternative ways of coding it.

I don't say that negatively. The Nusphere Phped product includes a profiler that lets you see the relative "performance" of every PHP statement. Generally we are going to get the biggest performance increases (improvements) by reducing traffic between client and server ... for instance caching css and javascript ... and by reducing both database and file system IO. After that we can sometimes find particular PHP statements that are "pigs" and find alternatives for them.
View user's profile Send private message Visit poster's website
Guardian2003
Site Admin


Joined: Aug 28, 2003
Posts: 6373
Location: Vsetin, Czech Republic

PostPosted: Thu Apr 02, 2009 2:25 am Reply with quote Back to top

Al good points!
I'm still on the fence about the DIR read though I can see now why it is there. I guess it depends if it falls over gracefully in the scenarion that the module is listed in the DB but the directory is actually not there.

In any event, the current methodology is far superior to what standard nuke had - there were several functions doing this at every page load, at least now there is only the one.
View user's profile Send private message Send e-mail Visit poster's website
testy1
Involved
Involved


Joined: Apr 06, 2008
Posts: 483

PostPosted: Thu Apr 02, 2009 4:12 am Reply with quote Back to top

fkelly wrote:
You could probably find some other block to deactivate that would yield an even greater performance gain.


The modules block is the only standard block with RN that is what I consider a bottleneck, Although It's only a bottleneck when you compare it to the rest of the blocks.

Overall it is probably not that bad, but compared to the other blocks its very naughty Smile

EDIT: suppose we need to remember, we are talking in milliseconds lol
View user's profile Send private message
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 16987
Location: Kansas

PostPosted: Thu Apr 02, 2009 7:09 am Reply with quote Back to top

The immediate issue is to correct the logic error I mentioned above.
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
fkelly
Moderator


Joined: Aug 30, 2005
Posts: 3186
Location: near Albany NY

PostPosted: Thu Apr 02, 2009 7:14 am Reply with quote Back to top

Actually, on a couple of sites that I support, the administrator (who is not a programmer by any means) has deactivated the modules block and used the wysiwyg editor to replace it with a better looking (larger text, highlights etc.) set of links to "areas" she wants to accent. If you are not going to be swapping modules in and out willy-nilly and you are only using a subset of the standard Nuke modules and blocks, this approach makes a lot of sense. But of course that's not relevant to your initial discussion of the performance of the standard RN modules block.
View user's profile Send private message Visit poster's website
testy1
Involved
Involved


Joined: Apr 06, 2008
Posts: 483

PostPosted: Thu Apr 02, 2009 4:14 pm Reply with quote Back to top

Raven wrote:
The immediate issue is to correct the logic error I mentioned above.


argh, ok I get it now, I thought you meant the changes you made didn't work.So there is an actual problem with current module block.
View user's profile Send private message
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 16987
Location: Kansas

PostPosted: Thu Apr 02, 2009 4:56 pm Reply with quote Back to top

Raven wrote:
It really says while ($file = readdir($handle)) { ? That will always resolve to TRUE! It should read while ($file == readdir($handle)) {
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
testy1
Involved
Involved


Joined: Apr 06, 2008
Posts: 483

PostPosted: Thu Apr 02, 2009 5:54 pm Reply with quote Back to top

I changed it according to the php site and it seem to work alright

Code:

while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
    //while ($file = readdir($handle)) {
          if ($file == $title) {
              $a = 1;
          }
      }
    }
View user's profile Send private message
duck
Involved
Involved


Joined: Jul 03, 2006
Posts: 267

PostPosted: Thu Apr 02, 2009 7:02 pm Reply with quote Back to top

Raven wrote:
Raven wrote:
It really says while ($file = readdir($handle)) { ? That will always resolve to TRUE! It should read while ($file == readdir($handle)) {



I think they are ignoring you Raven? Laughing
View user's profile Send private message
evaders99
Former Moderator in Good Standing


Joined: Apr 30, 2004
Posts: 3221

PostPosted: Thu Apr 02, 2009 7:30 pm Reply with quote Back to top

Actually Raven, readdir is using a directory resource. It isn't a logical variable comparison, rather its the transaction of putting data into $file that is being used to continue the loop.

readdir will continue to return data from the file handle until it is exhausted. It will return false when there is nothing left. The single = logic is completely correct here.
Only registered users can see links on this board!
Get registered or login to the forums!
View user's profile Send private message Visit poster's website
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 16987
Location: Kansas

PostPosted: Thu Apr 02, 2009 10:58 pm Reply with quote Back to top

Evaders,

tetsy1 has the correct way and that makes sense. If you read the link you posted you will see why I was complaining Smile. The way it's written in block-modules.php is wrong.

php.net states:

/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
echo "$file\n";
}

/* This is the WRONG way to loop over the directory. */
while ($file = readdir($handle)) {
echo "$file\n";
}
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
evaders99
Former Moderator in Good Standing


Joined: Apr 30, 2004
Posts: 3221

PostPosted: Thu Apr 02, 2009 11:05 pm Reply with quote Back to top

I understand, it's not the same as what you posted though. (for duck's sake) I don't think anyone is being ignored Smile
Code:

while ($file == readdir($handle)) {

This is completely not correct, for those viewing this post - just have to be careful where you're putting singe = and double == operations:)
View user's profile Send private message Visit poster's website
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 16987
Location: Kansas

PostPosted: Thu Apr 02, 2009 11:17 pm Reply with quote Back to top

Good point! I saw the error but in my haste I got locked on the = vs. ==. I will modify my post above. I have also entered a Mantis issue.
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
Display posts from previous:       
Post new topic   Reply to topic

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Forums ©
 

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2002-2011 by Raven

You can syndicate our news using the file xml

CSE HTML Validator Helped Clean up This Page! [Valid RSS] valid RSS 2.0 Valid robots.txt Stop Spam Harvesters, Join Project Honey Pot

Website engines core code is © copyright by PHP-Nuke but has been heavily patched and modified by myself and others.
PHP-Nuke is a free software released under the GNU/GPL.


:: fisubice phpbb2 style by Daz :: PHP-Nuke theme by www.nukemods.com ::
:: fisubice Theme Modified by the RavenNuke™ Team ::

:: W3C CSS Compliance Validation :: W3C HTML 4.01 Transitional Compliance Validation ::

zerosum