0

I want to run different php scripts based on result of execution of previous script (via AJAX), but I can't implement needed logic inside one script (and one SFTP connection) because decisions on which script to run next must be made by a user.

So my question is: is it ok to establish a new SFTP connection ( $sftp->login() ) every time I run a script using phpseclib?

If it is, then is there a limit on how many connections are allowed per some time frame?

If not, is there a way to "store" current connection and check if it has timed out (if it is applicable in this case) on every new script execution? Or some other "best practice" for this case?

blinkapec
  • 11
  • 1
  • 3
  • "_If it is, then is there a limit on how many connections are allowed per some time frame?_". That would depend more on the SSH server than on the SSH client. Is the SSH server OpenSSH or what? I'd post this question (omitting the bit about phpseclib since that's not relevant) on either superuser.com or serverfault.com – neubert Jul 02 '20 at 13:13
  • "_If not, is there a way to "store" current connection and check if it has timed out (if it is applicable in this case) on every new script execution? Or some other "best practice" for this case?_". You could use https://reactphp.org/ I suppose but other than by doing something like that... not really, no. – neubert Jul 02 '20 at 13:14
  • _is it ok to establish a new SFTP connection ( $sftp->login() ) every time I run a script using phpseclib?_ can you clarify how often (interval) you want to make a new SFTP connection (to run a script)? – Ivo Mori Jul 02 '20 at 14:02
  • @neubert Thank you, I'll try doing so. – blinkapec Jul 02 '20 at 21:21
  • @Ivo Mori Up to 1 per second. – blinkapec Jul 02 '20 at 21:23
  • Have no specific experiences regarding your case (mind you) – still _Up to 1 per second_ seems a lot and really feels like you should re-use your SSH connection – as @neubert pointed out, whether a lot of individual connections will work or not will depend on the SSH server configuration but also on available server resources. If there are no other solution design options left to you then you're left only with testing it out – but even if it works you may end up with a shaky overall solution. – Ivo Mori Jul 02 '20 at 23:17
  • @Ivo Mori Thanks for the clarification. Ok, I'll try to test the "shaky" solution and see if I'll have problems with it, because it seems like other ways are sort of more complex. For example php daemons or advised by _neubert_ ReactPHP library (which is kind of a daemon too if I understood correctly). – blinkapec Jul 03 '20 at 07:58

0 Answers0