But in this case you have 2 database. One is 'master' and another one is 
'default'. So when you are saving data to 'master' and updating data by 
'default' or deleting data by 'default'. Then how this 2 database will be 
synchronized. Data can be lost or any damage? Can you tell me the complete 
flow of this strategy? 



On Friday, February 11, 2011 5:39:52 PM UTC+6, majna wrote:
>
> Cleaner solution for master/slave using callbacks (or Behavior) 
>
> function beforeSave() { 
>     $this->useDbConfig = 'master'; 
>     return true; 
> } 
>
> function afterSave() { 
>     $this->useDbConfig = 'default'; 
>     return true; 
> } 
>
> function beforeDelete() { 
>     $this->useDbConfig = 'master'; 
>      return true; 
> } 
>
> function afterDelete() { 
>     $this->useDbConfig = 'default'; 
>      return true; 
> } 
>
>
> http://bakery.cakephp.org/articles/eagerterrier/2007/05/26/load-balancing-and-mysql-master-and-slaves-2
>  
>
> On Feb 10, 6:14 pm, ibejohn818 <john.c.ha...@gmail.com> wrote: 
> > This what I am using. 
> > === 
> > class AppModel extends Model { 
> > 
> >         public function save($data = null, $validate = true, $fieldList 
> = 
> > array()) { 
> > 
> >                 $this->useDbConfig = 'master'; 
> > 
> >                 $success = parent::save($data,$validate,$fieldList); 
> > 
> >                 $this->useDbConfig = 'default'; 
> > 
> >                 return $success; 
> > 
> >         } 
> > 
> >         public function saveAll($data = null, $options = array()) { 
> > 
> >                 $this->useDbConfig = 'master'; 
> > 
> >                 $status = parent::saveAll($data,$options); 
> > 
> >                 $this->useDbConfig = 'default'; 
> > 
> >                 return $status; 
> > 
> >         } 
> > 
> >         public function updateAll($fields, $conditions = true) { 
> > 
> >                 $this->useDbConfig = 'master'; 
> > 
> >                 $status = parent::updateAll($fields,$conditions); 
> > 
> >                 $this->useDbConfig = 'default'; 
> > 
> >                 return $status; 
> > 
> >         } 
> > 
> >         public function delete($id = null, $cascade = true) { 
> > 
> >                 $this->useDbConfig = "master"; 
> > 
> >                 $status = parent::delete($id,$cascade); 
> > 
> >                 $this->useDbConfig = 'default'; 
> > 
> >                 return $status; 
> > 
> >         } 
> > 
> > } 
> > 
> > ==== 
> > 
> > For multiple Slaves you should use a load balancer to RoundRobin 
> > Balance the requests to your slaves. 
> > 
> > On Feb 10, 9:05 am, Okto Silaban <o...@silaban.net> wrote: 
> > 
> > > That's what I'm trying to do. 
> > > I've setup 1 master and 2 slaves. But CakePHP doesn't support read & 
> write 
> > > query separation. 
> > > So, do you have any information how can I split the read & write 
> query? 
> > > *other than rewrite all my models 
> > 
> > > thanks. 
> > 
> > > On Wed, Feb 9, 2011 at 10:03 AM, Dr. Tarique Sani <
> tariques...@gmail.com>wrote: 
> > 
> > > > Have you split the reads and the writes? 
> > 
> > > > All the writes go to the master which is on a server of its own and 
> > > > the reads are from the slaves which are typically on the same 
> machine 
> > > > as the webserver and of course use very aggressive caching 
> > 
> > > > Cheers 
> > > > Tarique

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to