* @param integer $timeout
* @param array $options
*/
- public function __construct($host, $port, $timeout = 30) {
+ public function __construct($host, $port, $timeout = 30, $options = array()) {
$this->host = $host;
$this->port = $port;
- $this->resource = @fsockopen($host, $port, $this->errorNumber, $this->errorDesc, $timeout);
+ if (!preg_match('/^[a-z0-9]+:/', $this->host)) $this->host = 'tcp://'.$this->host;
+
+ $context = stream_context_create($options);
+ $this->resource = @stream_socket_client($this->host.':'.$this->port, $this->errorNumber, $this->errorDesc, $timeout, STREAM_CLIENT_CONNECT, $context);
if ($this->resource === false) {
throw new SystemException('Can not connect to ' . $host, 0, $this->errorDesc);
}
*/
public function execute() {
// connect
- $remoteFile = new RemoteFile(($this->useSSL ? 'ssl://' : '').$this->host, $this->port, $this->options['timeout']);
+ $remoteFile = new RemoteFile(($this->useSSL ? 'ssl://' : '').$this->host, $this->port, $this->options['timeout'], array(
+ 'ssl' => array(
+ 'peer_name' => $this->originHost
+ )
+ ));
if ($this->originUseSSL && PROXY_SERVER_HTTP) {
if ($this->useSSL) throw new SystemException("Unable to proxy HTTPS when using TLS for proxy connection");