Whole site in class

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shivam0101
Forum Contributor
Posts: 197
Joined: Sat Jun 09, 2007 12:09 am

Whole site in class

Post by shivam0101 »

Hello,

How to build whole website in class files? What structure I should follow? I am using php with mysql

Thanks
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

A whole web site should not be in class files. You will need regular .php files, template files (if you're doing templating), css files, etc.

Classes should be used for performing a specific task, or a group of similarly related tasks. Even if you want to go completely object oriented, using a framework, or design pattern, all of your files will not be in classes.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Re: Whole site in class

Post by AKA Panama Jack »

shivam0101 wrote:Hello,

How to build whole website in class files? What structure I should follow? I am using php with mysql

Thanks
You would only want to do this if you want to have one of the slowest web sites around that can't support very many simultaneous accesses without overloading the CPU.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You're question is a very loaded question. What is your intent with your site? What is your hardware set up and your system's current application architecture? Why do you want (or need or think you need) a setup like this?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Whole site in class

Post by Christopher »

shivam0101 wrote:How to build whole website in class files? What structure I should follow? I am using php with mysql
I think the poster means using OO to build the site, not all in one class.

I would recommend look at some PHP frameworks like the Zend Framework, Cake, Symfony, Code Igniter, etc. There are many excellent frameworks available. One of them will probably be in the style you prefer. You can use one of them or model your own code on their code.

And your site will perform fine despite what Panama Jack always says. There are thousands of sites around based on PHP OO frameworks.
(#10850)
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

You would only want to do this if you want to have one of the slowest web sites around that can't support very many simultaneous accesses without overloading the CPU.
You can't substantiate that in any way.
shivam0101
Forum Contributor
Posts: 197
Joined: Sat Jun 09, 2007 12:09 am

Post by shivam0101 »

Thanks for replying.

This is how i made, since i this is the first time i am making class to make a site, i am very confused and i am changing the structure many times.

This is the present structure i am following.



Each class in seperate files.

1. A class for sql statements

2. A class for client

3. A class for admin

4. A class for general - methods which are general to both client and admin

5. A class to link all this.- I will be calling this class object to access the methods of other classes.



But after going through, viewtopic.php?t=72041&highlight= i think i made a mistake. Since the site is allmost over. I can only alter a small portion and it may take more time to redo. Can any one please suggest a better way of altering.

Thanks.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

ole wrote:
You would only want to do this if you want to have one of the slowest web sites around that can't support very many simultaneous accesses without overloading the CPU.
You can't substantiate that in any way.
Actually it can be if you take the time. One of the best cases it to use the Zend Framework, class nightmare from hell to create a site and then do the same thing using mainly procedural coding with just a couple of classes for database and templating. Then use a web site stress testing package to test the number of simultaneous connection each design can handle. You will find the design using the Zend Framework is horribly slow and can't even come close to the number of page accesses per second of the virtually non-class version. I know I have tested stuff like this to make sure.

It's a inherent problem with PHP in creating objects from classes. The classes themselves are just as fast as procedural code after they have been created. It's the creation part that is dog slow in all versions of PHP. If you decide to take the time and actually test this yourself you will see I am right.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

shivam0101 wrote:But after going through, viewtopic.php?t=72041&highlight= i think i made a mistake. Since the site is allmost over. I can only alter a small portion and it may take more time to redo. Can any one please suggest a better way of altering.
Your classes are not quite right, but you are headed in the right direction. Your next site will be a little better. Look at the frameworks I listed. They will give you ideas.
(#10850)
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

George Schlossnagle, and he's not the first, mentions in his presentation that object overhead make up only a tiny fraction for the performance of the application when compared with the database (page 8 ). This is of course a typical case, things things vary depending on what you are writing and how you have written them.
One of the best cases it to use the Zend Framework, class nightmare from hell to create a site and then do the same thing using mainly procedural coding with just a couple of classes for database and templating. Then use a web site stress testing package to test the number of simultaneous connection each design can handle. You will find the design using the Zend Framework is horribly slow and can't even come close to the number of page accesses per second of the virtually non-class version. I know I have tested stuff like this to make sure.
Did you use a profiler? There were probably specific things about ZF that made it slow, for instance the ZF front controller always starts a session. On some systems this can potentially be quite an expensive operation considering a garbage clean-ups are performed at that time.
It's a inherent problem with PHP in creating objects from classes.
This is the first time I've ever heard this.
Post Reply