You can use the phpsocks library for this. It allows you to connect to a destination host through a SOCKS5 server and tunnel TCP traffic (TLS and UDP are also supported). Username/password authentication is supported, as well as no authentication.