setDescription('Test defined proxy configuration!') ->addOption('url', '', InputOption::VALUE_REQUIRED, 'Url to reach on test') ; } protected function doExecute(InputInterface $input, OutputInterface $output) { $proxiesConfig = $this->container['conf']->get(['network-proxies']); $urlTest = $input->getOption('url'); if ($urlTest == null) { $urlTest = 'www.google.fr'; } // test http-proxy if (isset($proxiesConfig['http-proxy']) && $proxiesConfig['http-proxy']['enabled'] && $proxiesConfig['http-proxy']['host'] && $proxiesConfig['http-proxy']['port']) { $output->writeln("Begin to check http proxy, maybe it's take a few seconds ...."); $httpProxy = $proxiesConfig['http-proxy']; $client = new Client([ 'http_errors' => true, 'proxy' => $httpProxy['host'] . ':' . $httpProxy['port'] ]); try { $response = $client->get($urlTest); $output->writeln("Test outgoing connection with proxy " .$httpProxy['host'] . ':' . $httpProxy['port']." success with status code : " . $response->getStatusCode() . " "); } catch(\Exception $e) { $output->writeln("Outgoing connection error with proxy " . $httpProxy['host'] . ':' . $httpProxy['port'] . " , " . $e->getMessage() . ""); } } // TODO: add test for ftp and socket proxy return 0; } }