Ruby 中跨 AJAX 调用访问通用 FTP 连接资源池的方法?
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以为您拥有的每个工作程序/应用程序进程打开一个连接。例如,对于乘客:
对于Rails,这将进入
environment.rb
。也就是说,我不确定这是否是个好主意,因为我不太使用 ftp。
You can open a connection for each worker/app process you have. For example, with passenger:
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.
我最终使用全局变量(例如 $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.