Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Author Topic: breaking down the snews.php  (Read 3371 times)

quaker

  • Newbie
  • *
  • Karma: 0
  • Posts: 15
breaking down the snews.php
« on: January 18, 2008, 07:35:34 pm »

has anyone tried to break this large file into smaller pc?

say admin.php
login.php
config.php
post.php

?
i know this might see like redoing the wheel.
but it would be easier to edit live each page that uploading changes to 1 file.


also im about to release a quick and simple gallery for snews  via upload of files to directory and lightbox pulls the images from folder.

Q
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Re: breaking down the snews.php
« Reply #1 on: January 18, 2008, 07:44:00 pm »

1 - Has anyone tried to break this large file into smaller pc? say...
      admin.php
      login.php
      config.php
      post.php
I know this might see like redoing the wheel. But it would be easier to edit live each page that uploading changes to 1 file.

2 - Also im about to release a quick and simple gallery for snews  via upload of files to directory and lightbox pulls the images from folder.
Q
1 - Yes. You can move functions out of the snews.php file and into new files with names similar to the function-name to make the easier to identify and remember. I have done this in the current MENU and MESU packages... by moving function-specific files into a mods folder within the root. When you do this, of course, you also need to re-include the new files so they are available to work in sNews. So you add them to the top of the index.php file in strings in the same format as the one already there for snews.php... putting them under it. Or... as is the case with my MEMU and MESU packages... I've moved all the include strings into a config.php file... along with the database (and other) configuration setting arrays... and just include the config.php file at the top of index.php. Either way, it works.

2 - New gallery configurations are always welcome. We'll look forward to testing yours out when it's ready.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

centered

  • Guest
Re: breaking down the snews.php
« Reply #2 on: January 18, 2008, 08:34:13 pm »

I have broken down the massive file into pieces too:
1. db configs - config.php
2. languages - lang.php
3. admin - admin.php
4. center broken to - center() - centerBody(); - center body has everything else for the articles
Logged

Joost

  • Guest
Re: breaking down the snews.php
« Reply #3 on: January 19, 2008, 01:51:35 am »

Cutting up snews.php for convenience is one thing. However, including many files is bad for performance as the code is recompiled every time a file is included. The following trick limits the amount of includes. The code represents an admin part in function center.

Code: [Select]
<?php
if (
$_SESSION[db('website').'Logged_In'] == token()) {
switch ($action) {
case 'administration': include('administration.php'); return; break;
case 'settings': include('settings.php'); return; break;
case 'categories': include('admin_categories.php'); return; break;
case 'admin_category': include('form_categories.php'); return; break;
//etc. etc

/*NOTE: create a function call inside the include like form_categories(); */
}
}
?>


Logged

centered

  • Guest
Re: breaking down the snews.php
« Reply #4 on: January 19, 2008, 07:10:26 am »

I have an idea.. related but not... why not dump all the language variables in the db? it's all text right? do the same as the settings.....
Logged

centered

  • Guest
Re: breaking down the snews.php
« Reply #5 on: January 19, 2008, 01:47:17 pm »

However, including many files is bad for performance as the code is recompiled every time a file is included.

Do you have data backing that up?  The difference would be miniscule and the only slow downs would be code or db optimizations or lack thereof.  My 1.4 test install is just as fast as codie's get_id mod for 1.6 and it is broken up into many files as I described above
Logged

Joost

  • Guest
Re: breaking down the snews.php
« Reply #6 on: January 19, 2008, 03:18:00 pm »

Do you have data backing that up?  The difference would be miniscule and the only slow downs would be code or db optimizations or lack thereof.  My 1.4 test install is just as fast as codie's get_id mod for 1.6 and it is broken up into many files as I described above
Can't find my source any more, Jason. I found it a few month ago and it was one of the real gurus, perhaps Lerdorf. Anyway, as I recall it, includes should be limited to no more than 10 and only when needed (Your example shows only 5 includes). It was a talk about good coding practice.
For what it is worth: Include paths should look like ./snews.php,  /var/something/site/folder/snews.php instead of snews.php. Also for better performance.
 
« Last Edit: January 19, 2008, 03:21:33 pm by Joost »
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Re: breaking down the snews.php
« Reply #7 on: January 19, 2008, 03:44:41 pm »

Anyway, as I recall it, includes should be limited to no more than 10 and only when needed (Your example shows only 5 includes). It was a talk about good coding practice.
That may explain why I am experiencing noticably slower page-load times with 16 or more additional function files being included (along with snews.php) within the config.php file in a few of my offline projects. I thought also it might be caused by excessive use of javascript-enabled expandable panels and pop-ups.

I don't think the issue of limiting the number of file-inclusions  necessarily applies generically to all CMS packages. For instance, take a look inside phpNuke and you'll find hundreds of files in several folders... and that structure does not appear to seriously impede performance... keeping in mind that phpNuke is one of the phattest CMSs out there and (understandibly) not as quick as a default sNews install to begin with.

So... I suppose we are learning that sNews... in its current form... does have its limitations when it comes to modularity and expansion. Perhaps we should keep in mind that we are taking it into directions that Luka never intended it to go in when he authored the main core a few versions back.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

centered

  • Guest
Re: breaking down the snews.php
« Reply #8 on: January 19, 2008, 04:40:27 pm »

Can't find my source any more, Jason. I found it a few month ago and it was one of the real gurus, perhaps Lerdorf. Anyway, as I recall it, includes should be limited to no more than 10 and only when needed (Your example shows only 5 includes). It was a talk about good coding practice.
 

I too would agree 10 inlcudes are too much.  Also use require instead of include.  Requires outputs a error message, includes does not.
Logged

centered

  • Guest
Re: breaking down the snews.php
« Reply #9 on: January 19, 2008, 04:43:27 pm »

Anyway, as I recall it, includes should be limited to no more than 10 and only when needed (Your example shows only 5 includes). It was a talk about good coding practice.
That may explain why I am experiencing noticably slower page-load times with 16 or more additional function files being included (along with snews.php) within the config.php file in a few of my offline projects. I thought also it might be caused by excessive use of javascript-enabled expandable panels and pop-ups.

I don't think the issue of limiting the number of file-inclusions  necessarily applies generically to all CMS packages. For instance, take a look inside phpNuke and you'll find hundreds of files in several folders... and that structure does not appear to seriously impede performance... keeping in mind that phpNuke is one of the phattest CMSs out there and (understandibly) not as quick as a default sNews install to begin with.


Doug,
I think certain files only call the files they need. I don't think a full core is taking in hundreds of files....
Logged

Joost

  • Guest
Re: breaking down the snews.php
« Reply #10 on: January 19, 2008, 05:07:50 pm »

@Doug

hundreds of files in a cms, doesn't necessarily mean they are all included at the same time.That was what I've tried to explain. When page /sitemap/ is called, a file is included containing function sitemap(). The file containing function contact() is not needed on that page and therefore not included.

So when slicing up sNews.php, we don't have to worry about the amount of pieces. Just make sure to include only what's needed.
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Re: breaking down the snews.php
« Reply #11 on: January 19, 2008, 06:25:00 pm »

@Doug
hundreds of files in a cms, doesn't necessarily mean they are all included at the same time.That was what I've tried to explain. When page /sitemap/ is called, a file is included containing function sitemap(). The file containing function contact() is not needed on that page and therefore not included.
So when slicing up sNews.php, we don't have to worry about the amount of pieces. Just make sure to include only what's needed.
I understand what you mean... and I know phpNuke doesn't include a whack of files in the core engine all at once.
I think I will compile another engine file consolidating all of the functions - now isolated in separate files - into the one engine file and see if there is any improvement on page-load times.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Re: breaking down the snews.php
« Reply #12 on: January 19, 2008, 08:12:08 pm »

Quick Page-load Test results:
Ran tests on my most heavily modifed project. It is an MEMU package with Admin Tip Pop-ups, Bakercad's switchable templates, and the ability to post both Pages and Articles to Categories and SubCategories. In its current configuration... it has 16 separate function files within a mods folder, all of which are called into action (along with snews.php) in a config.php file. The language array is also separated into its own languages folder.

I ran page-load tests on the above configuration, and also on a new engine file with all of the 16 files' functions consolidated into the one file (no additional includes). I did 10 page-loads of the Home page, and of the first Admin Panel, averaged them, and compared the average results to find a gain or loss. The results were interesting.

On the Home Page tests, the consolidated file experienced a slight gain of just less than 1% (.009728% quicker)... while in the Admin Page tests, the consolidated file showed a loss (greater loading time) of just under 1% (.009681% slower).

These tests are not conclusive, of course, but they do indicate that there really isn't much of a difference between having all the functions in one big file or having them broken down into... 18 files actually... with the language array in its own file as well.

The increased loading time I am experiencing is... I am sure... due to the amount of javascript activity I have incorporated into the subject project. I am not concerned about its loading time, but it is definitely slower than a default snews.php file. But then it also has a lot more functionality built into it than the default package... so this is to be expected.
« Last Edit: January 19, 2008, 08:14:04 pm by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

quaker

  • Newbie
  • *
  • Karma: 0
  • Posts: 15
Re: breaking down the snews.php
« Reply #13 on: January 20, 2008, 05:10:21 pm »

side note:

i took 3 scripts and put them together for my gallery.
1.lightbox
2.simplegallery script
3. functions to pull images from a folder

i had some help with the php and making it work right.

but this is a quick demo:
http://modelcrowd.com/guzzz.php

Once i get back home i will compile the files in a zip and give the link to download and i will make a simple integration readme.
I have released this gallery on punres.org (quaker is my nick on punbb and punres) as lightbox gallery.
So, it will fit in any php file system.

what i have done with snews is made a very good friend a photography site using snews. i have modified some of the snews functions to only include what he needed.
basically he needed a way to talk about his models and have a few photos.
once i get the site completely done i will give links out.
i will be creating a credits page and will include snews, and other scripts that i used to create his site and the propper copyright info

due to the fact that i remove all info off the main page! I still believe in giving credit and right to the respective groups.


Q


 
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Re: breaking down the snews.php
« Reply #14 on: January 20, 2008, 06:32:06 pm »

side note:
i took 3 scripts and put them together for my gallery.
1.lightbox
2.simplegallery script
3. functions to pull images from a folder
i had some help with the php and making it work right.

Once i get back home i will compile the files in a zip and give the link to download and i will make a simple integration readme.
Due to the fact that i remove all info off the main page! I still believe in giving credit and right to the respective groups.
We'll be looking forward to seeing your package when you have it available.  :)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU