通过AJAX调用访问Ruby中的通用FTP连接资源池的方法? [英] A way to access common FTP connection resource pool in Ruby across AJAX calls?

查看:210
本文介绍了通过AJAX调用访问Ruby中的通用FTP连接资源池的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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

有一种方式,我可以以某种方式存储FTP连接资源对象在一些公共内存池和重新访问连接资源对象与未来的AJAX调用?我试过Memcached,但它看起来像是不可能存储连接资源。也许我可以将它们存储在一个线程,以某种方式访问​​他们在那里?任何其他想法?

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.

推荐答案

我最后使用全局变量(例如$ 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.

这篇关于通过AJAX调用访问Ruby中的通用FTP连接资源池的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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