Page 1 of 1

Whole site in class

Posted: Sun Aug 26, 2007 12:02 am
by shivam0101
Hello,

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

Thanks

Posted: Sun Aug 26, 2007 12:16 am
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.

Re: Whole site in class

Posted: Sun Aug 26, 2007 12:53 am
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.

Posted: Sun Aug 26, 2007 1:32 am
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?

Re: Whole site in class

Posted: Sun Aug 26, 2007 3:08 am
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.

Posted: Sun Aug 26, 2007 6:34 am
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.

Posted: Sun Aug 26, 2007 6:52 am
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.

Posted: Sun Aug 26, 2007 4:07 pm
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.

Posted: Sun Aug 26, 2007 5:43 pm
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.

Posted: Sun Aug 26, 2007 7:59 pm
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.