How do you proxy though a server using ssh (socks…) using php’s CURL?

后端 未结 5 881
梦谈多话
梦谈多话 2021-02-10 00:27

I want to use ssh, something like this:

ssh -D 9999 username@ip-address-of-ssh-server

But within php CURL, but I don\'t really see how this cou

5条回答
  •  无人共我
    2021-02-10 01:08

    To open the SSH tunnel only for the duration of your script, you probably would need to use PHP forks. In one process, open the SSH tunnel (-D - you need to do some work to make sure you're not colliding on ports here), and in the other process, use CURL with socks proxy config. When your transfer is done, signal the ssh fork to terminate so the connection gets torn down.

    Keep in mind that while the tunnel is open, other users on the same machine can also proxy on that port if they wanted to. With that in mind, it might be a better idea to use the -L 1234:remotehost:80 flag, and just get the URL http://localhost:1234/some/uri

    If things go wrong with this, you may find orphaned SSH tunnels on your server though, so I would call this somewhat fragile.

提交回复
热议问题