Pro Yearly is on sale from $80 to $50! »

Working with Database Replications in CakePHP

2377be1c3f33751ea7c73a7bd8d58996?s=47 T. MOTOOKA
November 09, 2019

Working with Database Replications in CakePHP

9 Nov 2019
CakeFest 2019 in Tokyo, Japan

2377be1c3f33751ea7c73a7bd8d58996?s=128

T. MOTOOKA

November 09, 2019
Tweet

Transcript

  1. 8PSLJOHXJUI %BUBCBTF3FQMJDBUJPOT CZ5.0500," $BLF'FTUJO5PLZP

  2. "CPVUUIF4QFBLFS w 5BEBIJTB.0500," w 5XJUUFS!U@NPUPPLB w (JU)VCNPUPPLB w $3."QQMJDBUJPO%FWFMPQFS w

    EFQFOETPO$BLF1)1
 TJODF w MPWFT47(1%'pMFT
  3. "HFOEB w 8IBUT3FQMJDBUJPOT  w )PXUP6TF  w 1JUGBMMT w

    -PDBM%FWFMPQNFOU&OWJSPONFOU
  4. 8IBUT3FQMJDBUJPO

  5. "QQMJDBUJPOXJUI3FQMJDBUJPO .BTUFS %BUBCBTF 3FQMJDB %BUBCBTF "QQMJDBUJPO 4FSWFST 6TFST BDDFTT */4&3561%"5&

    TUBUFNFOUT SFQMJDBUJPO
  6. "QQMJDBUJPOXJUI3FQMJDBUJPO .BTUFS %BUBCBTF 3FQMJDB %BUBCBTF "QQMJDBUJPO 4FSWFST 6TFST BDDFTT */4&3561%"5&

    TUBUFNFOUT ☠
  7. "QQMJDBUJPOXJUI3FQMJDBUJPO .BTUFS %BUBCBTF 3FQMJDB %BUBCBTF "QQMJDBUJPO 4FSWFST 6TFST BDDFTT 4&-&$5TUBUFNFOU

  8. )PXUP6TF

  9. 1SPYZ4FSWFS .BTUFS %BUBCBTF 3FQMJDB %BUBCBTF "QQMJDBUJPO 4FSWFST 6TFST BDDFTT */4&3561%"5&

    TUBUFNFOUT SFQMJDBUJPO 1SPYZ 4FSWFS 4&-&$5 TUBUFNFOU
  10. "QQMJDBUJPO$PEF .BTUFS %BUBCBTF 3FQMJDB %BUBCBTF "QQMJDBUJPO 4FSWFST 6TFST BDDFTT 4&-&$5TUBUFNFOU

    */4&3561%"5&4&-&$5 TUBUFNFOUT SFQMJDBUJPO
  11. 4USBUFHJFT w %FGBVMU.BTUFS4USBUFHZ w %FGBVMU3FQMJDB4USBUFHZ

  12. 8IFSFUP*NQMFNFOU w BQQQIQ w 3FRVJSFE.FUIPET w changeConnectionToMaster w changeConnectionToReadReplica w

    8IFSF  w *OKFDUJOHBOBCTUSBDUTVCDMBTTPG5BCMF w #FIBWJPVS
  13. BQQQIQFYBNQMF

  14. "CTUSBDU4VCDMBTTPG5BCMF w *UMPPLTMJLF"QQ.PEFMPO$BLF1)1Y w &BTZUPHFUIFMQPG*%&TDPEFDPNQMFUJPO

  15. #FIBWJPVS w -FTT#SFBLJOHDIBOHF w &BTZUPSFVTFUIFDPEF

  16. $PEF&YBNQMF w %FGBVMU.BTUFS4USBUFHZ w 6TFUIFSFQMJDBPOMZPOIFBWZRVFSJFT w *NQMFNFOUUIFTXJUDIJOHNFUIPETJOB#FIBWJPVS w "XIPMFBQQMJDBUJPOSFQPTJUPSZ
 IUUQTHJUIVCDPNNPUPPLBDBLFQIQXJUI

    SFQMJDBUJPO
  17. 1JUGBMMT w 5SBOTBDUJPOT w .JHSBUJPOT w 3FQMJDBUJPO-BH

  18. 5SBOTBDUJPOT w %0/05 w DIBOHFDPOOFDUJPOEVSJOHBUSBOTBDUJPO w FYFD4&-&$5TUBUFNFOUPO3FQMJDB

  19. .JHSBUJPOT w PO%FGBVMU3FQMJDB4USBUFHZ w bin/cake migrations migrate --connection master w

    PO%FGBVMU.BTUFS4USBUFHZ w
  20. 3FQMJDBUJPO-BH w 5JNFDPOTVNFECFGPSFOFXEBUBBSSJWFTUP3FQMJDB w T UZQJDBMMZ w %FQFOETPOMPBE

  21. 3FQMJDBUJPO-BH // Controller public function add() { $article = $this->Articles->newEntity();

    if ($this->request->is('post')) { $article = $this->Articles->patchEntity($article, $this->request->getData()); if ($this->Articles->save($article)) { $this->Flash->success(__('Your article has been saved.')); return $this->redirect(['action' => 'index']); } .... } public function index() { // use ReadReplica for this action $this->Articles->changeConnectionToReadReplica(); $articles = $this->Paginator->paginate($this->Articles->find()); $this->set(compact('articles')); }
  22. -PDBM%FW&OWJSPONFOUT w *EFBMMZ QSFQBSF.Z42-TFSWFSTPOZPVSMPDBM w XJUIBTFUUJOHPG%FMBZFE3FQMJDBUJPO w

  23. 3FBE0OMZ6TFS w JTIFMQGVMUPEFUFDUUIFCVHXSJUJOHPOSFQMJDB w JTFBTZUPTFUVQ w DBOUTJNVMBUFSFQMJDBUJPOMBHT

  24. 6OJU5FTU w UFTUEBUBTPVSDFBMTPTIPVMECFSFQMJDBUFE
 JGZPVSFQMJDBUF w $*DPOTJEFSBUJPOT w :PVS$*FOWTVQQPSUTSFQMJDBUJPO  w

    SFBEPOMZVTFSNJHIUIFMQ
  25. 3FGFSFODFT w 3'$3FBE8SJUFEBUBCBTFTQMJUUJOH
 IUUQTHJUIVCDPNDBLFQIQDBLFQIQJTTVFT w &YBNQMF*NQMFNFOUBUJPO
 IUUQTHJUIVCDPNNPUPPLBDBLFQIQXJUI SFQMJDBUJPO w .Z42-3FGFSFODF.BOVBM


    %FMBZFE3FQMJDBUJPO
 IUUQTEFWNZTRMDPNEPDSFGNBOFO SFQMJDBUJPOEFMBZFEIUNM
  26. 5IBOL:PV &OKPZ3FQMJDBUJPOT