Ruby 中跨 AJAX 调用访问通用 FTP 连接资源池的方法?

发布于 2024-10-08 06:52:36 字数 336 浏览 0 评论 0原文

我有一个 Web 应用程序,它与外部服务器建立许多 FTP 或 SFTP 连接。它的界面使用 AJAX,通过 AJAX,我获取远程 FTP 服务器上的文件列表,并将其返回到客户端浏览器。

每次运行 AJAX 调用时,我都必须重新连接到远程服务器并重新进行身份验证。这需要大量的额外时间。

有没有一种方法可以将 FTP 连接资源对象存储在某个公共内存池中,并通过将来的 AJAX 调用重新访问连接资源对象?我尝试了 Memcached,但看起来无法在那里存储连接资源。也许我可以将它们存储在一个线程中并以某种方式在那里访问它们?还有其他想法吗?

我总是可以让一个守护进程管理连接并充当代理,但这感觉有点矫枉过正。

I have a web application which establishes many FTP or SFTP connections with outside servers. Its interface uses AJAX, and via AJAX I get file listings on remote FTP servers and return those to the client browser.

Each time I run an AJAX call, I have to reconnect to the remote server and reauthenticate. This takes a ton of extra time.

Is there a way I can somehow store FTP connection resource objects in some common memory pool and re-access to the connection resource objects with future AJAX calls? I tried Memcached, but it looks like it's not possible to store connection resources there. Maybe I could store them in a thread and somehow access them there? Any other ideas?

I could always have a daemon manage connections and act as a proxy, but that feels overkill.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ぺ禁宫浮华殁 2024-10-15 06:52:36

您可以为您拥有的每个工作程序/应用程序进程打开一个连接。例如,对于乘客:

if defined?(PhusionPassenger)
  PhusionPassenger.on_event(:starting_worker_process) do |forked|
    if forked
      # connect to ftp server
    end
  end
end

对于Rails,这将进入environment.rb

也就是说,我不确定这是否是个好主意,因为我不太使用 ftp。

You can open a connection for each worker/app process you have. For example, with passenger:

if defined?(PhusionPassenger)
  PhusionPassenger.on_event(:starting_worker_process) do |forked|
    if forked
      # connect to ftp server
    end
  end
end

With Rails this would go into environment.rb.

That said, I'm not sure if this is a great idea though since I don't use ftp much.

[旋木] 2024-10-15 06:52:36

我最终使用全局变量(例如 $my_global)来完成这项工作。我有一个 ConnectionPooler 单例类,它管理存储在哈希中的连接。简单如馅饼。

I ended up making this work using global variables (eg. $my_global). I have a ConnectionPooler singleton class which manages connections stored in a hash. Easy as pie.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文