1

I am writing a site in PHP and I am noticing that the page is taking 3-5 seconds to load (from a remote server), which is unacceptable. The software relies on around 12 classes to function correctly. I was wondering how much of a performance gain I would get if I rewrote most of the classes to just use regular php functions.

Thanks for any input.

Edit: I rely primarily on Redis, and using a simple MySQL query here and there.

hakre
  • 193,403
  • 52
  • 435
  • 836
Colum
  • 3,844
  • 1
  • 22
  • 26
  • Won't make much difference probably. You may want to look at profiling the code using something like Xdebug to find where your bottlenecks are. – ADW Apr 26 '11 at 21:53
  • Another case of misdirected micro-optimizations :( Benchmark. Be surprised/corrected. Learn. –  Apr 26 '11 at 21:57

4 Answers4

5

Functions or classes should make little to no difference (totally negligible) : that's not what is making your website / application slow.


Hard to give you more information, as we don't know how your setup looks like, but you might want to take a look at the answer I posted to this question : it contains some interesting ideas, when it comes to performances of a PHP application.


BTW: 12 classes is really not a big number of classes, if I may...

Community
  • 1
  • 1
Pascal MARTIN
  • 395,085
  • 80
  • 655
  • 663
2

Rewriting all the application in procedural programming is probably the worst thing you can ever do. Object oriented programming is not about performance gain but writing programmer-friendly and easily maintainable applications (among others).

You should not ever think about rewriting an OO application procedural. That's not the purpose. If you ever have bigger resource consumption using OO rather than procedural programming (and that is very unlikely) you should probably think about better scaling the app. Hardware nowadays is not that expensive.

On the other hand, your application has many possible bottlenecks and OO is probably not even on the list.

Did you check:

  • your Internet connection?
  • your server's Internet connection?
  • your ping loss to your server?
  • your server's configuration? (Apache/Nginx/Lighttpd or whatever it is)
  • your database server's configuration?
  • your database queries?
  • your server's load?
  • the timing for a connection to Redis?
  • your firewall's rules for the ports used by Redis?
  • your Redis' configuration? (maxclients, timeout)

If you answered NO to at least one question above, please do check that and if the problem persists, let me know!

Bogdan Constantinescu
  • 5,296
  • 4
  • 39
  • 50
1

The difference will probably not even be measurable.

Your problem most definitely isn't your code per se, but the way you access the database. Make sure your tables are appropriately indexed and you will see a substantial drop in page load times. You can use EXPLAIN SELECT ... to get further info on how a query actually runs and why it performs badly.

NikiC
  • 100,734
  • 37
  • 191
  • 225
0

You wont find much of a difference, if anything at all between functions and classes.

Chances are, one or more of your classes is written inefficiently, or relies on something that is. Examples could include waiting on a remote server, image processing, some databases (such as overloaded databases) or countless other methods. You should try to profile your code to see where the problem lies.

shmeeps
  • 7,725
  • 2
  • 27
  • 35