title: How to use fsockopen (or compatible) with SOCKS proxies in PHP?
body: <p>I've coded a non-evil, non-spammy IRC bot in PHP, using <code>fsockopen</code> and related functions. It works. However, the problem is that I need to support proxies (preferably SOCKS5, but HTTP is also OK if that is somehow easier, which I doubt). This is not supported by <code>fsockopen</code>.</p>
  
  <p>I've gone through all search results for "PHP fsockopen proxy" and related queries. I know of all the things that don't work, so please don't link to one of them.</p>
  
  <p>The PHP manual page for fsockopen mentions the function <code>stream_socket_client()</code> as </p>
  
  <blockquote>
    <p>similar but provides a richer set of options, including non-blocking connection and the ability to provide a stream context.</p>
  </blockquote>
  
  <p>This sounded promising at first, supposedly allowing me to just replace the <code>fsockopen</code> call with <code>stream_socket_client</code> and specify a proxy, maybe via a "stream context"... but it doesn't. Or does it? I'm very confused by the <a href="http://php.net/manual/en/function.stream-socket-client.php" rel="nofollow noreferrer">manual</a>.</p>
  
  <p>Please note that it must be a PHP code solution; I cannot pay for "Proxifier" or use any other external software to "wrap around" this.</p>
  
  <p>All the things I've tried seem to always result in me getting a bunch of empty output from the server, and then the socket is forcefully closed. Note that the proxy I'm trying with works when I use HexChat (a normal IRC client), with the same network, so it's not the proxies themselves that are at fault.</p>