1. CakePHP Master/Slave
*) Add default (slave as for query) setting in database. php, and master for saving
*) Define a new replicate behavior
<? Php
Class ReplicationBehavior extends ModelBehavior {
Public function beforeSave ($ Model ){
$ Model-> useDbConfig = master;
}
Public function afterSave ($ Model ){
$ Model-> useDbConfig = default;
}
Public function setServer ($ Model, $ server ){
$ Model->__ backupConfig = $ Model-> useDbConfig;
$ Model-> useDbConfig = $ server;
}
Public function afterFind ($ Model ){
If (! Empty ($ Model->__ backupConfig )){
$ This-> useDbConfig = $ Model->__ backupConfig;
}
$ Model->__ backupConfig = null;
}
Public function save ($ data = null, $ validate = true, $ whitelist = array ()){
$ This-> Replication-> beforeSave ($ this );
Return parent: save ($ data, $ validate, $ whitelist );
}
}
?>
*) Set $ actAs to have replicate behavior in your base app model
$ ActAs = array (Replicate );
*) Call the setServer method in your controller to determine which database you want to use for instant query after save
If ($ this-> Deal-> saveAll ($ this-> data, array (validate => first ))){
$ This-> Deal-> setServer (master );
$ Deal = $ this-> Deal-> find (first, array (
Conditions => array (slug => $ this-> data [Deal] [slug]),
Fields => array (id)
));
2. how to use xhprof (a php benchmark tool developed by facebook)
Http://techportal.ibuildings.com/2009/12/01/profiling-with-xhprof/
3. MySQL load-balancing
Mysql-load-balancing-proxy-trafficscript "> http://www.zeus.com/community/articles/building-mysql-load-balancing-proxy-trafficscript
4. ssl
Using lidate secure operations to single domain: https://lang.secure.jigocity.com
Keep track of referer links in http header
Redirect back to the original referer when done