• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 342
  • Last Modified:

Using single class in the all website script pages

I am having about one single class with about 3,500 lines of code, the whole website will be based on this class, so if the website has pages likes: member.php, login.php, signup.php, etc... all of them will use that single class to process most of the website functions.

Can that affect the server memory since it will probably load 3,500 line in the memory each time any member access any page?
0
Mohamed Abowarda
Asked:
Mohamed Abowarda
  • 2
4 Solutions
 
MarsMCommented:
That would not be a problem. 3500 lines would be less than (say 100 characters per line) 350 kilobytes. Frameworks like cakephp have many more lines and that is also not a problem in my experience.
0
 
eriksmtkaCommented:
Each time a page is loaded, the PHP engine reads the file, parses it, compiles it and processes it.  So, it will be doing a lot of that.  The performance penalty would probably be minimal, but if I were you, I would only include what you need for each stage of the process.

One other thing you could do is look in to the "bcompiler" PECL library.  This will give you the benefit of already having the PHP engine "parsed and compiled" the code.
0
 
MarsMCommented:
Actually, php is not compiled. It is interpreted and this means that it is interpreted each time it is run. Only the part that is needed is interpreted and as I stated before, it is small some loading it is fast. Compiling php can be done, but if you want to change anything in the source code you will have to recompile it. The speedup is about 40% (if I remember correctly from articles). My advise is to just use the class as is unless you have a real high traffic site.
0
 
Ray PaseurCommented:
I usually agree with eriksmtka but this time I disagree.  The performance "penalty" associated with reading a file includes I/O overhead from disk.  This means locating the file, reading the file, etc.  Disk I/O operations are about 100,000 X slower than in-memory operations.  My preference is to load ONE large file, containing all of the classes, functions and definitions needed for the application.  No disrespect meant to the PHP guys who wrote the autoloader -- it's useful in a development and debugging environment and that is what they work in.  But as a practical matter in the world of high-performance web applications you want the minimum number of I/O operations and that means the fewest number of include() calls.

Memory is not a problem.  Just buy more.  It's amazingly cheap.  Same is true of disk storage.  A gigabyte of online storage costs about the same as the amount of toilet paper you use to wipe your ass.  It's just not worth trying to economize on these things at the expense of robust application performance.

Best regards to all, and Happy New Year, ~Ray
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now