简体   繁体   English

在 laravel 项目中同步 2 个 mysql 数据库的最佳解决方案

[英]best solution to sync 2 mysql databases in a laravel project

I have a laravel project that is supposed to run in a localhost.我有一个应该在本地主机中运行的 laravel 项目。 but we needed to add the ability to do some modification while user of the app is away from his pc that the app runs on it's host.但是我们需要添加在应用程序的用户离开他的电脑时进行一些修改的能力,该应用程序在其主机上运行。 I know i can deploy the whole project in an online server but this solution is not an option till now.我知道我可以将整个项目部署在在线服务器上,但这个解决方案直到现在还不是一个选择。 we have only a weak online server (it's slower a lot than localhost);我们只有一个弱的在线服务器(它比本地主机慢很多); so we can use this weak online server for these situations when the user wants to do some modifications remotely which would happen from time to time almost two or three times a day while the localhost will have the heavy work of the rest of the day which may be more than 3 or 4 hundreds processes a day.因此,当用户想要远程进行一些修改时,我们可以将这个弱在线服务器用于这些情况,这几乎每天会不时发生两到三次,而本地主机将承担当天 rest 的繁重工作,这可能一天超过三四百个流程。 i can't make the whole load on the online server while it's very slow like that and we don't need online benefits a lot, just for those two or three times remote modifications that the app user may or may not need, so i can't trade off localhost speed for online benefits which i need only two or three times a day.我不能在在线服务器上完成全部负载,而它非常慢,而且我们不需要很多在线好处,只是对于应用程序用户可能需要或可能不需要的两到三倍远程修改,所以我不能以 localhost 速度换取在线利益,而我每天只需要两到三次。 what solution can i do.我能做什么解决方案。 i knew about master-slave and master-master replication but it's not an option too.我知道主从复制和主从复制,但这也不是一个选择。

is there any ideas and thank you in advance.有什么想法吗,提前谢谢你。

-------------- about the two environments (local and online)------------ local is windows running xamp stack (apache, mysql, php) server is linux (don't know actually which distro but any way i can't install any tools there... just php packages with composer) -------------- 关于两种环境(本地和在线)------------ 本地是 windows 运行 xamp 堆栈(apache,mysql,php)服务器是linux(实际上不知道哪个发行版,但无论如何我都无法在那里安装任何工具......只是 php 包与作曲家)

I had the same problem for uploading my laravel project我在上传 laravel 项目时遇到了同样的问题

just use FileZilla to upload your project, even with the worst internet speed you can do it.只需使用 FileZilla 上传您的项目,即使您可以使用最差的互联网速度。 and save yourself the trouble.并为自己省去麻烦。

To answer your question, If I were you, I will create a sync_data table in the application.为了回答您的问题,如果我是您,我将在应用程序中创建一个sync_data表。 And the sync data table will have the responsibility to record the changes occurring for various entities.同步数据表将负责记录各种实体发生的变化。

For example, if you change customer data in the localhost, you will save an entry to sync_data like type=customer, id=10, action=update, synced=No .例如,如果您在 localhost 中更改客户数据,您将在sync_data中保存一个条目,例如type=customer, id=10, action=update, synced=No And using a cron you can push these updates -fetching the customer record by saved id- to your online server in regular intervals, which will not make your online server busy.并且使用 cron,您可以定期将这些更新(通过保存的 id 获取客户记录)推送到您的在线服务器,这不会使您的在线服务器忙碌。 Furthermore, your online users will have the latest data at least.此外,您的在线用户至少将拥有最新数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM