Ticket #6700: mythweb-6700-add_ip_address_to_MythBackend_class.2.patch

File mythweb-6700-add_ip_address_to_MythBackend_class.2.patch, 2.4 KB (added by sphery <mtdean@…>, 10 years ago)

Updated patch. Better handles defaults.

  • classes/MythBackend.php

    old new  
    2828    private $fp                     = null;
    2929    private $connected              = false;
    3030    private $host                   = '127.0.0.1';
    31     private $port                   = 6543;
    32     private $port_http              = 6544;
     31    private $ip                     = '127.0.0.1';
     32    private $port                   = null;
     33    private $port_http              = null;
    3334
    34     static function find($host = null, $port = 6543) {
     35    static function find($host = null, $port = null) {
    3536        static $Backends = array();
    3637
    3738    // Looking for the master backend?
     
    4950        return $Backend[$host][$port];
    5051    }
    5152
    52     function __construct($host, $port) {
     53    function __construct($host, $port = null) {
    5354        $this->host = $host;
    54         $this->port = $port;
     55        $this->ip = _or(setting('BackendServerIP', $this->host), $host);
     56        $this->port = _or($port, _or(setting('BackendServerPort', $this->host), 6543));
    5557        $this->port_http = _or(setting('BackendStatusPort', $this->host), _or(setting('BackendStatusPort'), 6544));
    5658    }
    5759
     
    6264    private function connect() {
    6365        if ($this->connected)
    6466            return;
    65         $this->fp = @fsockopen($this->host, $this->port, $errno, $errstr, 25);
     67        $this->fp = @fsockopen($this->ip, $this->port, $errno, $errstr, 25);
    6668        if (!$this->fp)
    67             custom_error("Unable to connect to the master backend at {$this->host}:{$this->port}.\nIs it running?");
     69            custom_error("Unable to connect to the master backend at {$this->ip}:{$this->port}".(($this->host == $this->ip)?'':" (hostname: {$this->host})").".\nIs it running?");
    6870        $this->connected = true;
    6971        socket_set_timeout($this->fp, 20);
    7072        $this->checkProtocolVersion();
     
    188190    }
    189191
    190192    public function httpRequest($path, $args = array()) {
    191         $url = "http://{$this->host}:{$this->port_http}/Myth/{$path}?";
     193        $url = "http://{$this->ip}:{$this->port_http}/Myth/{$path}?";
    192194        foreach ($args as $key => $value)
    193195            $url .= $key.'='.urlencode($value).'&';
    194196        return @file_get_contents($url);