Forum Moderators: coopster

Message Too Old, No Replies

too many php files

         

michlcamp

11:11 pm on Nov 10, 2005 (gmt 0)

10+ Year Member



I've been learning PHP as I go with a lot of trial and error and plenty or reading, too - and it's been working great, but I think I've missed something along the way.

It feels like I'm creating too many php files to make my site work...each one having a specific script or a single function on it, and I'm wondering if there's a way to put a lot of PHP functions/classes in one file and then call the specific scripts as needed from the php commands on other pages?

I use 'require' and 'include' here and there for saved snippets of code, but can I call specific snippets from a page with a lot of them on it? (sort of like the 'url_link#name.html' in HTML) or maybe like a "php stylesheet"...

Not sure I've been clear enough, but maybe some of you "PHP elders" know what I'm asking...

thanks in advance.
mc

lobo235

11:33 pm on Nov 10, 2005 (gmt 0)

10+ Year Member



My advice is to group as many similar PHP functions/classes together in a file as you can. Requiring or including too many separate PHP files can slow down your site. For example, group all database related functions/classes in one file and user/visitor/login related functions and classes in another. By separating things out a little bit but not too much you still have the flexibility to include only the scripts you need for the specific page. You may not need to use database functions on certain pages so why include them?

In summary, I think it is a good idea to separate common function into different includes but you should not have to include more than 3 or 4 files. On the other hand, if you find that you are including all 3 or 4 of the files on pretty much every page you are better off putting them all in one file and just including that.

I hope this proves useful.