什么是套接字声明,在Ruby on Rails database.yml中? [英] What is the socket declaration for, in Ruby on Rails database.yml?

查看:136
本文介绍了什么是套接字声明,在Ruby on Rails database.yml中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在config / database.yml中使用套接字声明是什么?

What's the use of socket declaration in config/database.yml ?

示例代码:

staging:
  adapter: mysql
  encoding: utf8
  database: (database)
  pool: 5
  username: (user)
  password: (pass)
  socket: /tmp/mysql.sock     # <--------- this line

我的应用程序工作,这行是否注释。那么是什么呢?

My app works, wether this line is commented or not. So what is it for ? What reasons can I have to leave it, comment it or change it's value ?

推荐答案

当两个程序想互相交谈时,我可以留下什么原因,评论或改变它的价值?通过网络,一个程序可能打开一个TCP连接(套接字)与另一个。第一个程序需要知道第二台计算机的IP地址和程序正在侦听的端口。

When two programs want to talk to each other over the network, one program might open up a TCP connection (a "socket") with the other one. The first program needs to know the IP address of the second computer and the port on which the program is listening.

在Linux上,当同一台计算机上的两个程序想要彼此交谈,他们仍然可以打开一个TCP连接。但是他们也可以通过套接字文件打开一个连接。 Linux使套接字文件API与TCP API非常相似,因此更新已通过TCP在网络上通信的程序也不是一个大问题,以支持通过套接字文件进行通信。 Socket文件比TCP快,但只有当两个程序都在同一台计算机上时才工作。

On Linux, when two programs on the same computer want to talk to each other, they can still open up a TCP connection. But they can also open up a connection via a "socket file". Linux makes the socket file API rather similar to the TCP API, so it's not a big deal to update a program that already communicates over the network via TCP to support communicating via socket files too. Socket files are faster than TCP, but only work when both programs are on the same computer.

这篇关于什么是套接字声明,在Ruby on Rails database.yml中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆