views:

49

answers:

2

Hi everyone!
I'm trying to write down some concrete ideas for a light framework (on PHP5), with the purpose to handle a lot of requests and to make it scale well in terms of high traffic eventualities. I've already started it, but I'm not really satisfied about the coding style, which is basically composed by simple classes and helpers, with a main one to load them all.

class Settings {
    // I provide settings for everyone and I'm called by everyone via singleton.
     // $settings = instance(Settings);
}

class Database {
    // I provide the db connection.
}

class Session {
    // I handle the sessions.
}

[...]

class Core {
    // I start every class we need.
}

The structure is a kinda basic one. APP is a public tree, SYSTEM is a private tree.

app
 |-- css
 |-- js
 |-- page_name
       |-- index.php
 [...]

system
 |-- settings
 |-- libs
 |-- helpers
 |-- langs
 [...]

Basically what I do is setting the paths in the constants on the index.php file, which calles a boot.php file that includes the libraries that we need (Settings, Database, Session), then includes the core.php file that starts every class using objects. Of course this is a synthesis.
I designed everything to be more independent from the core, so if I need, for example, some settings, I just refer to the settings class (by singleton), instead recall the core and then get the data.

The main problem is that I don't know if this "style" could be good for my goals, 'cause it looks nooby to me, compared to the others main frameworks. I don't also get why everyone uses things like Implements, Extends, Interface, or others, which I find more confusing than putting everything into a single class with public and private visibility or just using functions.
Can I get some advanced tips, examples, or whatever can help reaching my goals?

Thanks!

A: 

Have you looked at CodeIgniter? Seems to do everything you're doing. What is does (and looks like you're trying to do) is create a super object which loads and manages requests.

Josh K
Yeah, but it has a lot of features that I don't need, and tbh it would take a lot to readjust and trim down everything. But I'm trying to take inspiration from it, thats why I use a main object for everything! Thanks
eij
A: 

If you want to scale, here's some tips that are more important than coding structure:

  • Make it easy to cache PHP code to a file as static HTML to avoid unnecessary DB queries
  • Make it easy for the DB connection to use a master/slave configuration
  • Make it easy to use memcached

You'll need to use these types of things long before your coding structure becomes a problem, at least from a traffic scalability perspective. It may be more problematic from a maintenance perspective.

robbrit
Will do! But I don't wanna go too much ahead if I have a wrong structure.
eij