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.
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.
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.