title: TPROXY with libcurl or http:// streams under PHP
body: <p>I have a PHP app that acts as TPROXY between users and some HTTP resources, i.e. setting the socket in transparent mode by binding to users' IP for the outgoing connections:</p>
  
  <pre><code>socket_set_option($outgoing_socket, 0 /*SOL_IP*/, 19 /*IP_TRANSPARENT*/, 1);
  socket_bind($outgoing_socket, $incoming_ip, $incoming_port);
  </code></pre>
  
  <p>Got tired fighting with invalid request and response headers, etc. HTTP related stuff, so I'm looking for a much more robust solution like libcurl or http:// streams to take care of the protocol communication part, and to focus my attention only on the payload.</p>
  
  <p>The problem? I couldn't find a way to turn TPROXY mode of the underlying socket for both the solutions:</p>
  
  <ul>
  <li>unfortunately, CURLOPT_SOCKOPTFUNCTION doesn't seem to be supported
  in the PHP bindings of libcurl</li>
  <li>without setting IP_TRANSPARENT to the socket, http ['socket']['bind'] context wouldn't accept IPs not assigned to the current machine </li>
  </ul>
  
  <p>Any ideas how to solve my problem?</p>