简体   繁体   中英

Is it good practice to have multiple DB connections in Symfony2

I am working on an application which is largely dependent on another application's DB. So I was wondering should I create two database connections or run a Cron job on the servers to sync my databases?

My research says that I can have multiple connections but it will slow down the requests.

Thanks in advance

It's not good to rely on other's application DB. It can change eventually and nobody will tell you about it.

It's better to make API (REST, RPC, Queues, whatever) that should be working as promised. Even if DB changes, they can keep API format so you don't have to rewrite your application.

But API may be harder to implement. You can consider DB as unstable unreliable API and use it directly. If you need only read-only access make new DB user that has only read-only access.

Also if DB is at other host be prepared to:

  • have secure connection (only your IP should have access and it's good when connection is secure for example via private network)
  • have network issues - remote host may be slower, even up to timeout; make this assumption in your code (may be it can show part of information without remote data or just notify you about the problem)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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