CakePHP: tipsonssl, mysqlloadbalance, mas

Source: Internet
Author: User
1. CakePHPMaster/Slave & nbsp; *) adddefault (slaveasforquery) settingindatabase. php, andmasterforsaving & nbsp; *) defineanewreplicatebehavior & nbsp; & lt ;? Php & nbsp; & nb

1. CakePHP Master/Slave
*) Add default (slave as for query) setting in database. php, and master for saving
*) Define a new replicate behavior

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.