logger()->info(dt('No graphical display appears to be available, not starting browser.')); return false; } $host = parse_url($uri, PHP_URL_HOST); if (!$host) { // Build a URI for the current site, if we were passed a path. $site = drush_get_context('DRUSH_URI'); $host = parse_url($site, PHP_URL_HOST); $uri = $site . '/' . ltrim($uri, '/'); } // Validate that the host part of the URL resolves, so we don't attempt to // open the browser for http://default or similar invalid hosts. $hosterror = (gethostbynamel($host) === false); $iperror = (ip2long($host) && gethostbyaddr($host) == $host); if (!Drush::simulate() && ($hosterror || $iperror)) { $this->logger()->warning(dt('!host does not appear to be a resolvable hostname or IP, not starting browser. You may need to use the --uri option in your command or site alias to indicate the correct URL of this site.', ['!host' => $host])); return false; } if ($port) { $uri = str_replace($host, "localhost:$port", $uri); } if ($browser === true) { // See if we can find an OS helper to open URLs in default browser. if (drush_shell_exec('which xdg-open')) { $browser = 'xdg-open'; } else if (drush_shell_exec('which open')) { $browser = 'open'; } else if (!drush_has_bash()) { $browser = 'start'; } else { // Can't find a valid browser. $browser = false; } } $prefix = ''; if ($sleep) { $prefix = 'sleep ' . $sleep . ' && '; } if ($browser) { $this->logger()->success(dt('Opening browser !browser at !uri', ['!browser' => $browser, '!uri' => $uri])); if (!Drush::simulate()) { $pipes = []; proc_close(proc_open($prefix . $browser . ' ' . drush_escapeshellarg($uri) . ' 2> ' . drush_bit_bucket() . ' &', [], $pipes)); } return true; } } return false; } }