Ok i posted the solutions from a thread of Steven111 and myself in here, cos finally there's a proper place
Replace functions in mainfile.php with these to speed up page generations.
Credits to Steven111, Raven & myself
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);
}
_________________ Famous people never give their signature http://www.cpgnuke.com <- back online thanks to dedicatednow.com
Don't ask me to be admin on your site please
XtraX Lieutenant
Joined: Aug 23, 2003
Posts: 195
Posted:
Sun Feb 22, 2004 10:56 pm
No usando el nuke más
Last edited by XtraX on Fri Jan 21, 2005 1:13 am; edited 1 time in total
djmaze Captain
Joined: Nov 29, 2003
Posts: 566
Location: Netherlands
Posted:
Sun Feb 22, 2004 11:10 pm
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 http://www.cpgnuke.com <- back online thanks to dedicatednow.com
Don't ask me to be admin on your site please
XtraX Lieutenant
Joined: Aug 23, 2003
Posts: 195
Posted:
Sun Feb 22, 2004 11:20 pm
No usando el nuke más
Last edited by XtraX on Fri Jan 21, 2005 1:14 am; edited 1 time in total
diabluntd Nuke Soldier
Joined: Dec 19, 2003
Posts: 32
Posted:
Mon Feb 23, 2004 1:04 pm
i applied this patch and it's seemed to have knocked loading times in half (give or take a few).
Thanks!
Stephen2417 Major
Joined: Dec 26, 2003
Posts: 1135
Location: Bristolville, OH (US)
Posted:
Mon Feb 23, 2004 1:12 pm
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
djmaze Captain
Joined: Nov 29, 2003
Posts: 566
Location: Netherlands
Posted:
Mon Feb 23, 2004 2:21 pm
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 http://www.cpgnuke.com <- back online thanks to dedicatednow.com
Don't ask me to be admin on your site please
Stephen2417 Major
Joined: Dec 26, 2003
Posts: 1135
Location: Bristolville, OH (US)
Posted:
Mon Feb 23, 2004 2:25 pm
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
foxyfemfem Support Staff
Joined: Jan 23, 2003
Posts: 668
Location: USA
Posted:
Mon Feb 23, 2004 2:29 pm
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
_________________ If you shoot for the moon and miss, you'll still be amongst the stars.
djmaze Captain
Joined: Nov 29, 2003
Posts: 566
Location: Netherlands
Posted:
Mon Feb 23, 2004 3:02 pm
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.
_________________ Famous people never give their signature http://www.cpgnuke.com <- back online thanks to dedicatednow.com
Don't ask me to be admin on your site please
Stephen2417 Major
Joined: Dec 26, 2003
Posts: 1135
Location: Bristolville, OH (US)
Posted:
Mon Feb 23, 2004 3:25 pm
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.
djmaze Captain
Joined: Nov 29, 2003
Posts: 566
Location: Netherlands
Posted:
Mon Feb 23, 2004 3:43 pm
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
_________________ Famous people never give their signature http://www.cpgnuke.com <- back online thanks to dedicatednow.com
Don't ask me to be admin on your site please
Jeruvy Lieutenant
Joined: Jul 09, 2003
Posts: 293
Posted:
Tue Feb 24, 2004 8:08 am
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.
diabluntd Nuke Soldier
Joined: Dec 19, 2003
Posts: 32
Posted:
Tue Feb 24, 2004 1:01 pm
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?
NickABusey Nuke Soldier
Joined: Oct 19, 2003
Posts: 33
Location: Lititz, PA
Posted:
Tue Feb 24, 2004 5:40 pm
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!
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