You are missing our premiere tool bar navigation system! Register and use it for FREE!

NukeCops  
•  Home •  Downloads •  Gallery •  Your Account •  Forums • 
Readme First
- Readme First! -

Read and follow the rules, otherwise your posts will be closed
Modules
· Home
· FAQ
· Buy a Theme
· Advertising
· AvantGo
· Bookmarks
· Columbia
· Community
· Donations
· Downloads
· Feedback
· Forums
· PHP-Nuke HOWTO
· Private Messages
· Search
· Statistics
· Stories Archive
· Submit News
· Surveys
· Theme Gallery
· Top
· Topics
· Your Account
Who's Online
There are currently, 310 guest(s) and 0 member(s) that are online.

You are Anonymous user. You can register for free by clicking here
Nuke Cops :: View topic - Speedup mainfile.php [ ]
 Forum FAQ  •  Search  •   •  Memberlist  •  Usergroups   •  Register  •  Profile •    •  Log in to check your private messages  •  Log in

 
Post new topic  Reply to topicprinter-friendly view
View previous topic Log in to check your private messages View next topic
Poll :: This speed upgrade was usefull for me ?

Yes
61%
 61%  [ 64 ]
A bit
26%
 26%  [ 28 ]
No
11%
 11%  [ 12 ]
Total Votes : 104


Author Message
djmaze
Captain
Captain


Joined: Nov 29, 2003
Posts: 566

Location: Netherlands

PostPosted: Sun Feb 22, 2004 10:50 pm Reply with quoteBack to top

Ok i posted the solutions from a thread of Steven111 and myself in here, cos finally there's a proper place Smile

Replace functions in mainfile.php with these to speed up page generations.
Credits to Steven111, Raven & myself Wink

Code:
function is_active($module) {
    global $prefix, $db;
    static $save;
    if (is_array($save)) {
        if (isset($save[$module])) return ($save[$module]);
        return 0;
    }
    $sql = "SELECT title FROM ".$prefix."_modules WHERE active=1";
    $result = $db->sql_query($sql);
    while ($row = $db->sql_fetchrow($result)) {
        $save[$row[0]] = 1;
    }
    if (isset($save[$module])) return ($save[$module]);
    return 0;
}

Code:
function getusrinfo($user) {
    global $user_prefix, $db, $userinfo;
    static $userrow;
    if (!$user || $user == '') { return NULL; }
    if(!is_array($user)) {
        $user = base64_decode($user);
        $user = explode(":", $user);
    }
    if (is_array($userrow)) {
        if ($userrow['username'] == $user[1] && $userrow['user_password'] = $user[2]) {
            return $userrow;
        }
    }
    $sql = "SELECT * FROM ".$user_prefix."_users WHERE username='$user[1]' AND user_password='$user[2]'";
    $result = $db->sql_query($sql);
    if ($db->sql_numrows($result) == 1) {
        $userrow = $db->sql_fetchrow($result);
        return $userinfo = $userrow;
    }
    unset($userinfo);
}

Code:
function cookiedecode($user) {
    global $cookie, $db, $user_prefix;
    static $pass;
    if(!is_array($user)) {
        $user = base64_decode($user);
        $cookie = explode(":", $user);
    } else {
        $cookie = $user;
    }
    if (!isset($pass)) {
       $sql = "SELECT user_password FROM ".$user_prefix."_users WHERE username='$cookie[1]'";
       $result = $db->sql_query($sql);
       list($pass) = $db->sql_fetchrow($result);
    }
    if ($cookie[2] == $pass && $pass != "") { return $cookie; }
    unset($user);
    unset($cookie);
}

Code:
function get_theme() {
    global $user, $cookie, $Default_Theme;
    static $ThemeSelSave;
    if (isset($ThemeSelSave)) return ($ThemeSelSave);
    if(is_user($user)) {
        $user2 = base64_decode($user);
        $t_cookie = explode(":", $user2);
        if($t_cookie[9]=="") $t_cookie[9]=$Default_Theme;
        if(isset($theme)) $t_cookie[9]=$theme;
        if(!$tfile=@opendir("themes/$t_cookie[9]")) {
            $ThemeSel = $Default_Theme;
        } else {
            $ThemeSel = $t_cookie[9];
        }
    } else {
        $ThemeSel = $Default_Theme;
    }
    $ThemeSelSave = $ThemeSel;
    return($ThemeSel);
}

Code:
function is_admin($admin) {
    global $prefix, $db;
    static $adminSave;
    if (isset($adminSave)) return ($adminSave); //steve
    if(!is_array($admin)) {
        $admin = base64_decode($admin);
        $admin = explode(":", $admin);
    }
    $aid = $admin[0];
    $pwd = $admin[1];
    if ($aid != "" AND $pwd != "") {
        $aid = trim($aid);
        $sql = "SELECT pwd FROM ".$prefix."_authors WHERE aid='$aid'";
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $pass = $row['pwd'];
        if ($pass == $pwd && $pass != "") {
            return $adminSave = 1;
        }
    }
    return $adminSave = 0;
}

Code:
function is_user($user) {
    global $db, $user_prefix;
    static $userSave;
    if (isset($userSave)) return ($userSave);
    if (!is_array($user)) {
        $user = base64_decode($user);
        $user = explode(":", $user);
    }
    $uid = $user[0];
    $pwd = $user[2];
    $uid = intval($uid);
    if ($uid != "" AND $pwd != "") {
        $sql = "SELECT user_password FROM ".$user_prefix."_users WHERE user_id='$uid'";
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $pass = $row['user_password'];
        if ($pass == $pwd && $pass != "") {
            return $userSave = 1;
        }
    }
    return $userSave = 0;
}


Here's the thread where it came from (if it still exists)
http://nukecops.com/postt21077.html

_________________
Famous people never give their signature Rolling Eyes
http://www.cpgnuke.com <- back online thanks to dedicatednow.com
Don't ask me to be admin on your site please Exclamation
Find all posts by djmazeView user's profileSend private messageVisit poster's website
XtraX
Lieutenant
Lieutenant


Joined: Aug 23, 2003
Posts: 195


PostPosted: Sun Feb 22, 2004 10:56 pm Reply with quoteBack to top

No usando el nuke más


Last edited by XtraX on Fri Jan 21, 2005 1:13 am; edited 1 time in total
Find all posts by XtraXView user's profileSend private message
djmaze
Captain
Captain


Joined: Nov 29, 2003
Posts: 566

Location: Netherlands

PostPosted: Sun Feb 22, 2004 11:10 pm Reply with quoteBack to top

I've tested on Nuke 6.5 and Steven on 7.0.
Just make a backup of your mainfile.php then replace the codes and test yourself.

_________________
Famous people never give their signature Rolling Eyes
http://www.cpgnuke.com <- back online thanks to dedicatednow.com
Don't ask me to be admin on your site please Exclamation
Find all posts by djmazeView user's profileSend private messageVisit poster's website
XtraX
Lieutenant
Lieutenant


Joined: Aug 23, 2003
Posts: 195


PostPosted: Sun Feb 22, 2004 11:20 pm Reply with quoteBack to top

No usando el nuke más


Last edited by XtraX on Fri Jan 21, 2005 1:14 am; edited 1 time in total
Find all posts by XtraXView user's profileSend private message
diabluntd
Nuke Soldier
Nuke Soldier


Joined: Dec 19, 2003
Posts: 32


PostPosted: Mon Feb 23, 2004 1:04 pm Reply with quoteBack to top

i applied this patch and it's seemed to have knocked loading times in half (give or take a few).

Thanks!
Find all posts by diabluntdView user's profileSend private message
Stephen2417
Major
Major


Joined: Dec 26, 2003
Posts: 1135

Location: Bristolville, OH (US)

PostPosted: Mon Feb 23, 2004 1:12 pm Reply with quoteBack to top

Dang that did help. My loading times got cut in half too!!

Except im still getting about 3 secs, Is there any other ways of optomizing?

EDIT: Well its not realy 3 secs. Just when you first load the page it takes 3 secs. Then its about 2 secs. If you wanted to take a look at my site its...
*URL removed by Stephen*


Last edited by Stephen2417 on Thu May 20, 2004 11:39 am; edited 1 time in total
Find all posts by Stephen2417View user's profileSend private messageSend e-mailVisit poster's websiteAIM Address
djmaze
Captain
Captain


Joined: Nov 29, 2003
Posts: 566

Location: Netherlands

PostPosted: Mon Feb 23, 2004 2:21 pm Reply with quoteBack to top

Rainbow Brite wrote:
Dang that did help. My loading times got cut in half too!!

Except im still getting about 3 secs, Is there any other ways of optomizing?

EDIT: Well its not realy 3 secs. Just when you first load the page it takes 3 secs. Then its about 2 secs. If you wanted to take a look at my site its...
http://www.hesinc.org


Move to another host !

My host has accounts from $35 a year till $400 and the pages are fast enough for me although the server is sometimes down.

_________________
Famous people never give their signature Rolling Eyes
http://www.cpgnuke.com <- back online thanks to dedicatednow.com
Don't ask me to be admin on your site please Exclamation
Find all posts by djmazeView user's profileSend private messageVisit poster's website
Stephen2417
Major
Major


Joined: Dec 26, 2003
Posts: 1135

Location: Bristolville, OH (US)

PostPosted: Mon Feb 23, 2004 2:25 pm Reply with quoteBack to top

Good Suggestion, except I already paid for the whole year, I think that I have till october though.
They said that they are going to upgrade my server soon, so mabye it will be faster.

EDIT: I paid about $100/year, I got 2000 MB, 2000 Emails, & 60 GB Bandwith. If you wanted to check out the copmany it...
http://www.globat.com
Find all posts by Stephen2417View user's profileSend private messageSend e-mailVisit poster's websiteAIM Address
foxyfemfem
Support Staff
Support Staff


Joined: Jan 23, 2003
Posts: 668

Location: USA

PostPosted: Mon Feb 23, 2004 2:29 pm Reply with quoteBack to top

Hello,

Djmaze, that's a good tweak. Is there a way to tweak everything to speed up including the modules?

(ie:) Everything is based on nuke_users table. Therefore, is it possible to call the nuke user table only once via mainfile.php and all the other modules that rely on mainfile.php use that info without calling the user table again & again? (I hope that make sense).

(another example:) The homepage (index.php) file rely on the mainfile.php therefore, the nuke_user table load. Then surf to your account module, instead of your account reloading nuke_user table it use the previous load from the mainfile.php file. Every module retrieve information from the nuke users table therefore, why should it constantly call the user table if it has already been called from the mainfile.php. (ie: surf to the forums (rely on user table) surf to your account (rely on user table) etc. That within itself can speed up if only one call is made (mainfile.php) and everything else that has (include or require mainfile.php) can use what has already been called (nuke user table).

I hope that make sense Laughing

_________________
If you shoot for the moon and miss, you'll still be amongst the stars.
Find all posts by foxyfemfemView user's profileSend private message
djmaze
Captain
Captain


Joined: Nov 29, 2003
Posts: 566

Location: Netherlands

PostPosted: Mon Feb 23, 2004 3:02 pm Reply with quoteBack to top

Foxy,

making the code easier and faster is the the CPG-Nuke team thingy.
About calling nuke_users table: That can be far much more efficient.

But loading the whole table in memory is out of the question and a bid overhead don't you think ?

Now comes the SQL part i like most: "INNER JOIN" and "LEFT JOIN"
Those JOIN functions are easy to understand and reduce the the qeuries drastically.

For example:
You have a "who is online" module and the table of that module contains the "user_id" and "where"
Now you need to find the "Title" of where and the "username"

A normal PHP-Nuke function would be
Code:
$query = "SELECT * FROM ".$prefix."_who_where";
$result = sql_query($query, $dbi);
while ($row = sql_fetch_row($result)) {
    $query = "SELECT username FROM ".$user_prefix."_users WHERE user_id = $row[user_id]";
    $result2 = sql_query($query, $dbi);
    $row2 = sql_fetch_row($result2);
    // etc.
}


Now here my code optimiation
Code:
$query = "SELECT w.user_id, w.where, u.username FROM ".$prefix."_who_where AS w LEFT JOIN ".$user_prefix."_users AS u ON (u.user_id = w.user_id)";
$result = $db->sql_query($query);
while (list($user_id, $where, $username) = $db->sql_fetch_row($result)) {
    // etc.
}


With INNER JOIN only the left and right tables return a row if user_id exists in both.

A good example is block-Survey thatone uses about 25 SQL queries.
I managed to reduce that to only 3 queries.
http://cvs.sourceforge.net/viewcvs.py/phpnuke65-cpg/html/blocks/block-Survey.php

_________________
Famous people never give their signature Rolling Eyes
http://www.cpgnuke.com <- back online thanks to dedicatednow.com
Don't ask me to be admin on your site please Exclamation
Find all posts by djmazeView user's profileSend private messageVisit poster's website
Stephen2417
Major
Major


Joined: Dec 26, 2003
Posts: 1135

Location: Bristolville, OH (US)

PostPosted: Mon Feb 23, 2004 3:25 pm Reply with quoteBack to top

Hey djmaze, I think that you should be a moderator for speed freaks. Since thats all that you are trying to do with nuke, lol.
Find all posts by Stephen2417View user's profileSend private messageSend e-mailVisit poster's websiteAIM Address
djmaze
Captain
Captain


Joined: Nov 29, 2003
Posts: 566

Location: Netherlands

PostPosted: Mon Feb 23, 2004 3:43 pm Reply with quoteBack to top

Rainbow Brite wrote:
Hey djmaze, I think that you should be a moderator for speed freaks. Since thats all that you are trying to do with nuke, lol.

I already did and you don't wanna know how much time it cost the last 2 months to do it.

And guess what i have far much more surprises in my CVS.
When CPG-Nuke is released you will notice a lot of changes and finally fully HTML 4.01 compliant website due to 2 themes and fixed modules.
The big list will be released at the same time as CPG-Nuke.
But i couldn't resist to post a few things in these forums to get the atention of all of you and that there are people (not only me) that like a good, secure and fast CMS.

But as you can see on my sig image it's still very quiet Confused

_________________
Famous people never give their signature Rolling Eyes
http://www.cpgnuke.com <- back online thanks to dedicatednow.com
Don't ask me to be admin on your site please Exclamation
Find all posts by djmazeView user's profileSend private messageVisit poster's website
Jeruvy
Lieutenant
Lieutenant


Joined: Jul 09, 2003
Posts: 293


PostPosted: Tue Feb 24, 2004 8:08 am Reply with quoteBack to top

djmaze wrote:
I've tested on Nuke 6.5 and Steven on 7.0.
Just make a backup of your mainfile.php then replace the codes and test yourself.


Tested here on 6.8 and 6.9 as well.

J.
Find all posts by JeruvyView user's profileSend private messageICQ Number
diabluntd
Nuke Soldier
Nuke Soldier


Joined: Dec 19, 2003
Posts: 32


PostPosted: Tue Feb 24, 2004 1:01 pm Reply with quoteBack to top

ever since i did this i've had a "phantom user" in my user info block and site messenger block. Basically it's just a blank slot...

1. usera
2. userb
3.
4. userc
5. userd

i replaced my original mainfile.php back and after a few minutes the phantom user dissapeared. anyone?
Find all posts by diabluntdView user's profileSend private message
NickABusey
Nuke Soldier
Nuke Soldier


Joined: Oct 19, 2003
Posts: 33

Location: Lititz, PA

PostPosted: Tue Feb 24, 2004 5:40 pm Reply with quoteBack to top

It moved my average from 0.057 to 0.045. 20% increase, every little bit helps! Thanks! For hosting that's that fast at only $5 a month check out www.cogentdesigns.net!
Find all posts by NickABuseyView user's profileSend private messageVisit poster's websiteAIM Address
Display posts from previous:      
Post new topic  Reply to topicprinter-friendly view
View previous topic Log in to check your private messages View next 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



Powered by phpBB © 2001, 2005 phpBB Group

Ported by Nuke Cops © 2003 www.nukecops.com
:: FI Theme :: PHP-Nuke theme by coldblooded (www.nukemods.com) ::
Powered by TOGETHER TEAM srl ITALY http://www.togetherteam.it - DONDELEO E-COMMERCE http://www.DonDeLeo.com - TUTTISU E-COMMERCE http://www.tuttisu.it
Web site engine's code is Copyright © 2002 by PHP-Nuke. All Rights Reserved. PHP-Nuke is Free Software released under the GNU/GPL license.
Page Generation: 0.049 Seconds - 322 pages served in past 5 minutes. Nuke Cops Founded by Paul Laudanski (Zhen-Xjell)
:: FI Theme :: PHP-Nuke theme by coldblooded (www.nukemods.com) ::