开发者

Tips for a light PHP Framework

开发者 https://www.devze.com 2023-01-21 17:12 出处:网络
I\'m trying to write down some concrete ideas for a light framework (on PHP5), with the purpose to handle a lot of requests开发者_StackOverflow中文版 and to make it scale well in terms of high traffi

I'm trying to write down some concrete ideas for a light framework (on PHP5), with the purpose to handle a lot of requests开发者_StackOverflow中文版 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!


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消