如何构建Large Scale PHP架构?

Filed Under (PHP, SAAS, Tech) by mantian on 14-03-2009

Tagged Under : , ,

一、构建Large Scale Php代码框架要先了解什么是SNA的架构。

SNA的意思是Share Nothing Architecture,其实很简单,就3个意思:

1、类似Http请求,每个请求之间都是独立的,没有状态的;

2、共享的数据都放在数据存储层,如数据库中或分布式数据库中;

3、避免前端的控制;

SNA的框架带来如下好处:

1、容易部署负载均衡服务;

2、程序模块化划分更好;

3、容易开发和Debug;

4、避免导致数据存储中心出现大范围瘫痪;

二、不要在运行时采用模板技术

记住,PHP本身就是基于模板技术的语言,不要再引用另外一个了,如果有时候你不得不采用模板技术,那么千万不要在运行时采用模板技术;

三、采用APC Opcode Cache

详情见apc,对PHP有效的开放源高速缓冲储存器工具,它能够缓存opcode的php中间码。lfacebook也在采用Apc作为PHP加速器

四、推荐的框架如下:

php_app_arch

五、还有一些注意细节:

  • No more than 1 stat() per PHP file per request;
  • Add a stat cache to PHP’s expand_filepath code;
  • Don’t stat if Apache has already stat’ed the file;
  • Get rid of excessive stats in the streams code;
  • Remove ./ from include_path and use relative path includes;
  • Use just a single base dir in include_path;
  • No open_basedir or safe_mode;
  • Use non-PIC Apache DSO (gcc -prefer-non-pic;
  • Use platform-specific gcc flags;
  • ./configure –disable-all;
  • Plenty of custom extensions and limit RINIT;
  • Filter all user data by default;
  • No $_COOKIE for you;
  • Careful use of the session extension;
  • others….
FireStats icon Powered by FireStats
MC Inside