DiagnoseCommand.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Command;
  12. use Composer\Composer;
  13. use Composer\Factory;
  14. use Composer\Config;
  15. use Composer\Downloader\TransportException;
  16. use Composer\Repository\PlatformRepository;
  17. use Composer\Plugin\CommandEvent;
  18. use Composer\Plugin\PluginEvents;
  19. use Composer\Util\ConfigValidator;
  20. use Composer\Util\IniHelper;
  21. use Composer\Util\ProcessExecutor;
  22. use Composer\Util\HttpDownloader;
  23. use Composer\Util\StreamContextFactory;
  24. use Composer\SelfUpdate\Keys;
  25. use Composer\SelfUpdate\Versions;
  26. use Composer\IO\NullIO;
  27. use Symfony\Component\Console\Input\InputInterface;
  28. use Symfony\Component\Console\Output\OutputInterface;
  29. /**
  30. * @author Jordi Boggiano <j.boggiano@seld.be>
  31. */
  32. class DiagnoseCommand extends BaseCommand
  33. {
  34. /** @var HttpDownloader */
  35. protected $httpDownloader;
  36. /** @var ProcessExecutor */
  37. protected $process;
  38. /** @var int */
  39. protected $exitCode = 0;
  40. protected function configure()
  41. {
  42. $this
  43. ->setName('diagnose')
  44. ->setDescription('Diagnoses the system to identify common errors.')
  45. ->setHelp(
  46. <<<EOT
  47. The <info>diagnose</info> command checks common errors to help debugging problems.
  48. The process exit code will be 1 in case of warnings and 2 for errors.
  49. Read more at https://getcomposer.org/doc/03-cli.md#diagnose
  50. EOT
  51. )
  52. ;
  53. }
  54. /**
  55. * {@inheritdoc}
  56. */
  57. protected function execute(InputInterface $input, OutputInterface $output)
  58. {
  59. $composer = $this->getComposer(false);
  60. $io = $this->getIO();
  61. if ($composer) {
  62. $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'diagnose', $input, $output);
  63. $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
  64. $io->write('Checking composer.json: ', false);
  65. $this->outputResult($this->checkComposerSchema());
  66. }
  67. if ($composer) {
  68. $config = $composer->getConfig();
  69. } else {
  70. $config = Factory::createConfig();
  71. }
  72. $config->merge(array('config' => array('secure-http' => false)));
  73. $config->prohibitUrlByConfig('http://repo.packagist.org', new NullIO);
  74. $this->httpDownloader = Factory::createHttpDownloader($io, $config);
  75. $this->process = new ProcessExecutor($io);
  76. $io->write('Checking platform settings: ', false);
  77. $this->outputResult($this->checkPlatform());
  78. $io->write('Checking git settings: ', false);
  79. $this->outputResult($this->checkGit());
  80. $io->write('Checking http connectivity to packagist: ', false);
  81. $this->outputResult($this->checkHttp('http', $config));
  82. $io->write('Checking https connectivity to packagist: ', false);
  83. $this->outputResult($this->checkHttp('https', $config));
  84. $opts = stream_context_get_options(StreamContextFactory::getContext('http://example.org'));
  85. if (!empty($opts['http']['proxy'])) {
  86. $io->write('Checking HTTP proxy: ', false);
  87. $this->outputResult($this->checkHttpProxy());
  88. $io->write('Checking HTTP proxy support for request_fulluri: ', false);
  89. $this->outputResult($this->checkHttpProxyFullUriRequestParam());
  90. $io->write('Checking HTTPS proxy support for request_fulluri: ', false);
  91. $this->outputResult($this->checkHttpsProxyFullUriRequestParam());
  92. }
  93. if ($oauth = $config->get('github-oauth')) {
  94. foreach ($oauth as $domain => $token) {
  95. $io->write('Checking '.$domain.' oauth access: ', false);
  96. $this->outputResult($this->checkGithubOauth($domain, $token));
  97. }
  98. } else {
  99. $io->write('Checking github.com rate limit: ', false);
  100. try {
  101. $rate = $this->getGithubRateLimit('github.com');
  102. if (!is_array($rate)) {
  103. $this->outputResult($rate);
  104. } elseif (10 > $rate['remaining']) {
  105. $io->write('<warning>WARNING</warning>');
  106. $io->write(sprintf(
  107. '<comment>Github has a rate limit on their API. '
  108. . 'You currently have <options=bold>%u</options=bold> '
  109. . 'out of <options=bold>%u</options=bold> requests left.' . PHP_EOL
  110. . 'See https://developer.github.com/v3/#rate-limiting and also' . PHP_EOL
  111. . ' https://getcomposer.org/doc/articles/troubleshooting.md#api-rate-limit-and-oauth-tokens</comment>',
  112. $rate['remaining'],
  113. $rate['limit']
  114. ));
  115. } else {
  116. $this->outputResult(true);
  117. }
  118. } catch (\Exception $e) {
  119. if ($e instanceof TransportException && $e->getCode() === 401) {
  120. $this->outputResult('<comment>The oauth token for github.com seems invalid, run "composer config --global --unset github-oauth.github.com" to remove it</comment>');
  121. } else {
  122. $this->outputResult($e);
  123. }
  124. }
  125. }
  126. $io->write('Checking disk free space: ', false);
  127. $this->outputResult($this->checkDiskSpace($config));
  128. if ('phar:' === substr(__FILE__, 0, 5)) {
  129. $io->write('Checking pubkeys: ', false);
  130. $this->outputResult($this->checkPubKeys($config));
  131. $io->write('Checking composer version: ', false);
  132. $this->outputResult($this->checkVersion($config));
  133. }
  134. $io->write(sprintf('Composer version: <comment>%s</comment>', Composer::getVersion()));
  135. $platformOverrides = $config->get('platform') ?: array();
  136. $platformRepo = new PlatformRepository(array(), $platformOverrides);
  137. $phpPkg = $platformRepo->findPackage('php', '*');
  138. $phpVersion = $phpPkg->getPrettyVersion();
  139. if (false !== strpos($phpPkg->getDescription(), 'overridden')) {
  140. $phpVersion .= ' - ' . $phpPkg->getDescription();
  141. }
  142. $io->write(sprintf('PHP version: <comment>%s</comment>', $phpVersion));
  143. if (defined('PHP_BINARY')) {
  144. $io->write(sprintf('PHP binary path: <comment>%s</comment>', PHP_BINARY));
  145. }
  146. return $this->exitCode;
  147. }
  148. private function checkComposerSchema()
  149. {
  150. $validator = new ConfigValidator($this->getIO());
  151. list($errors, , $warnings) = $validator->validate(Factory::getComposerFile());
  152. if ($errors || $warnings) {
  153. $messages = array(
  154. 'error' => $errors,
  155. 'warning' => $warnings,
  156. );
  157. $output = '';
  158. foreach ($messages as $style => $msgs) {
  159. foreach ($msgs as $msg) {
  160. $output .= '<' . $style . '>' . $msg . '</' . $style . '>' . PHP_EOL;
  161. }
  162. }
  163. return rtrim($output);
  164. }
  165. return true;
  166. }
  167. private function checkGit()
  168. {
  169. $this->process->execute('git config color.ui', $output);
  170. if (strtolower(trim($output)) === 'always') {
  171. return '<comment>Your git color.ui setting is set to always, this is known to create issues. Use "git config --global color.ui true" to set it correctly.</comment>';
  172. }
  173. return true;
  174. }
  175. private function checkHttp($proto, Config $config)
  176. {
  177. $result = $this->checkConnectivity();
  178. if ($result !== true) {
  179. return $result;
  180. }
  181. $disableTls = false;
  182. $result = array();
  183. if ($proto === 'https' && $config->get('disable-tls') === true) {
  184. $disableTls = true;
  185. $result[] = '<warning>Composer is configured to disable SSL/TLS protection. This will leave remote HTTPS requests vulnerable to Man-In-The-Middle attacks.</warning>';
  186. }
  187. if ($proto === 'https' && !extension_loaded('openssl') && !$disableTls) {
  188. $result[] = '<error>Composer is configured to use SSL/TLS protection but the openssl extension is not available.</error>';
  189. }
  190. try {
  191. $this->httpDownloader->get($proto . '://repo.packagist.org/packages.json');
  192. } catch (TransportException $e) {
  193. if (false !== strpos($e->getMessage(), 'cafile')) {
  194. $result[] = '<error>[' . get_class($e) . '] ' . $e->getMessage() . '</error>';
  195. $result[] = '<error>Unable to locate a valid CA certificate file. You must set a valid \'cafile\' option.</error>';
  196. $result[] = '<error>You can alternatively disable this error, at your own risk, by enabling the \'disable-tls\' option.</error>';
  197. } else {
  198. array_unshift($result, '[' . get_class($e) . '] ' . $e->getMessage());
  199. }
  200. }
  201. if (count($result) > 0) {
  202. return $result;
  203. }
  204. return true;
  205. }
  206. private function checkHttpProxy()
  207. {
  208. $result = $this->checkConnectivity();
  209. if ($result !== true) {
  210. return $result;
  211. }
  212. $protocol = extension_loaded('openssl') ? 'https' : 'http';
  213. try {
  214. $json = $this->httpDownloader->get($protocol . '://repo.packagist.org/packages.json')->decodeJson();
  215. $hash = reset($json['provider-includes']);
  216. $hash = $hash['sha256'];
  217. $path = str_replace('%hash%', $hash, key($json['provider-includes']));
  218. $provider = $this->httpDownloader->get($protocol . '://repo.packagist.org/'.$path)->getBody();
  219. if (hash('sha256', $provider) !== $hash) {
  220. return 'It seems that your proxy is modifying http traffic on the fly';
  221. }
  222. } catch (\Exception $e) {
  223. return $e;
  224. }
  225. return true;
  226. }
  227. /**
  228. * Due to various proxy servers configurations, some servers can't handle non-standard HTTP "http_proxy_request_fulluri" parameter,
  229. * and will return error 500/501 (as not implemented), see discussion @ https://github.com/composer/composer/pull/1825.
  230. * This method will test, if you need to disable this parameter via setting extra environment variable in your system.
  231. *
  232. * @return bool|string
  233. */
  234. private function checkHttpProxyFullUriRequestParam()
  235. {
  236. $result = $this->checkConnectivity();
  237. if ($result !== true) {
  238. return $result;
  239. }
  240. $url = 'http://repo.packagist.org/packages.json';
  241. try {
  242. $this->httpDownloader->get($url);
  243. } catch (TransportException $e) {
  244. try {
  245. $this->httpDownloader->get($url, array('http' => array('request_fulluri' => false)));
  246. } catch (TransportException $e) {
  247. return 'Unable to assess the situation, maybe packagist.org is down ('.$e->getMessage().')';
  248. }
  249. return 'It seems there is a problem with your proxy server, try setting the "HTTP_PROXY_REQUEST_FULLURI" and "HTTPS_PROXY_REQUEST_FULLURI" environment variables to "false"';
  250. }
  251. return true;
  252. }
  253. /**
  254. * Due to various proxy servers configurations, some servers can't handle non-standard HTTP "http_proxy_request_fulluri" parameter,
  255. * and will return error 500/501 (as not implemented), see discussion @ https://github.com/composer/composer/pull/1825.
  256. * This method will test, if you need to disable this parameter via setting extra environment variable in your system.
  257. *
  258. * @return bool|string
  259. */
  260. private function checkHttpsProxyFullUriRequestParam()
  261. {
  262. $result = $this->checkConnectivity();
  263. if ($result !== true) {
  264. return $result;
  265. }
  266. if (!extension_loaded('openssl')) {
  267. return 'You need the openssl extension installed for this check';
  268. }
  269. $url = 'https://api.github.com/repos/Seldaek/jsonlint/zipball/1.0.0';
  270. try {
  271. $this->httpDownloader->get($url);
  272. } catch (TransportException $e) {
  273. try {
  274. $this->httpDownloader->get($url, array('http' => array('request_fulluri' => false)));
  275. } catch (TransportException $e) {
  276. return 'Unable to assess the situation, maybe github is down ('.$e->getMessage().')';
  277. }
  278. return 'It seems there is a problem with your proxy server, try setting the "HTTPS_PROXY_REQUEST_FULLURI" environment variable to "false"';
  279. }
  280. return true;
  281. }
  282. private function checkGithubOauth($domain, $token)
  283. {
  284. $result = $this->checkConnectivity();
  285. if ($result !== true) {
  286. return $result;
  287. }
  288. $this->getIO()->setAuthentication($domain, $token, 'x-oauth-basic');
  289. try {
  290. $url = $domain === 'github.com' ? 'https://api.'.$domain.'/' : 'https://'.$domain.'/api/v3/';
  291. return $this->httpDownloader->get($url, array(
  292. 'retry-auth-failure' => false,
  293. )) ? true : 'Unexpected error';
  294. } catch (\Exception $e) {
  295. if ($e instanceof TransportException && $e->getCode() === 401) {
  296. return '<comment>The oauth token for '.$domain.' seems invalid, run "composer config --global --unset github-oauth.'.$domain.'" to remove it</comment>';
  297. }
  298. return $e;
  299. }
  300. }
  301. /**
  302. * @param string $domain
  303. * @param string $token
  304. * @throws TransportException
  305. * @return array|string
  306. */
  307. private function getGithubRateLimit($domain, $token = null)
  308. {
  309. $result = $this->checkConnectivity();
  310. if ($result !== true) {
  311. return $result;
  312. }
  313. if ($token) {
  314. $this->getIO()->setAuthentication($domain, $token, 'x-oauth-basic');
  315. }
  316. $url = $domain === 'github.com' ? 'https://api.'.$domain.'/rate_limit' : 'https://'.$domain.'/api/rate_limit';
  317. $data = $this->httpDownloader->get($url, array('retry-auth-failure' => false))->decodeJson();
  318. return $data['resources']['core'];
  319. }
  320. private function checkDiskSpace($config)
  321. {
  322. $minSpaceFree = 1024 * 1024;
  323. if ((($df = @disk_free_space($dir = $config->get('home'))) !== false && $df < $minSpaceFree)
  324. || (($df = @disk_free_space($dir = $config->get('vendor-dir'))) !== false && $df < $minSpaceFree)
  325. ) {
  326. return '<error>The disk hosting '.$dir.' is full</error>';
  327. }
  328. return true;
  329. }
  330. private function checkPubKeys($config)
  331. {
  332. $home = $config->get('home');
  333. $errors = array();
  334. $io = $this->getIO();
  335. if (file_exists($home.'/keys.tags.pub') && file_exists($home.'/keys.dev.pub')) {
  336. $io->write('');
  337. }
  338. if (file_exists($home.'/keys.tags.pub')) {
  339. $io->write('Tags Public Key Fingerprint: ' . Keys::fingerprint($home.'/keys.tags.pub'));
  340. } else {
  341. $errors[] = '<error>Missing pubkey for tags verification</error>';
  342. }
  343. if (file_exists($home.'/keys.dev.pub')) {
  344. $io->write('Dev Public Key Fingerprint: ' . Keys::fingerprint($home.'/keys.dev.pub'));
  345. } else {
  346. $errors[] = '<error>Missing pubkey for dev verification</error>';
  347. }
  348. if ($errors) {
  349. $errors[] = '<error>Run composer self-update --update-keys to set them up</error>';
  350. }
  351. return $errors ?: true;
  352. }
  353. private function checkVersion($config)
  354. {
  355. $result = $this->checkConnectivity();
  356. if ($result !== true) {
  357. return $result;
  358. }
  359. $versionsUtil = new Versions($config, $this->httpDownloader);
  360. $latest = $versionsUtil->getLatest();
  361. if (Composer::VERSION !== $latest['version'] && Composer::VERSION !== '@package_version@') {
  362. return '<comment>You are not running the latest '.$versionsUtil->getChannel().' version, run `composer self-update` to update ('.Composer::VERSION.' => '.$latest['version'].')</comment>';
  363. }
  364. return true;
  365. }
  366. /**
  367. * @param bool|string|\Exception $result
  368. */
  369. private function outputResult($result)
  370. {
  371. $io = $this->getIO();
  372. if (true === $result) {
  373. $io->write('<info>OK</info>');
  374. return;
  375. }
  376. $hadError = false;
  377. $hadWarning = false;
  378. if ($result instanceof \Exception) {
  379. $result = '<error>['.get_class($result).'] '.$result->getMessage().'</error>';
  380. }
  381. if (!$result) {
  382. // falsey results should be considered as an error, even if there is nothing to output
  383. $hadError = true;
  384. } else {
  385. if (!is_array($result)) {
  386. $result = array($result);
  387. }
  388. foreach ($result as $message) {
  389. if (false !== strpos($message, '<error>')) {
  390. $hadError = true;
  391. } elseif (false !== strpos($message, '<warning>')) {
  392. $hadWarning = true;
  393. }
  394. }
  395. }
  396. if ($hadError) {
  397. $io->write('<error>FAIL</error>');
  398. $this->exitCode = max($this->exitCode, 2);
  399. } elseif ($hadWarning) {
  400. $io->write('<warning>WARNING</warning>');
  401. $this->exitCode = max($this->exitCode, 1);
  402. }
  403. if ($result) {
  404. foreach ($result as $message) {
  405. $io->write($message);
  406. }
  407. }
  408. }
  409. private function checkPlatform()
  410. {
  411. $output = '';
  412. $out = function ($msg, $style) use (&$output) {
  413. $output .= '<'.$style.'>'.$msg.'</'.$style.'>'.PHP_EOL;
  414. };
  415. // code below taken from getcomposer.org/installer, any changes should be made there and replicated here
  416. $errors = array();
  417. $warnings = array();
  418. $displayIniMessage = false;
  419. $iniMessage = PHP_EOL.PHP_EOL.IniHelper::getMessage();
  420. $iniMessage .= PHP_EOL.'If you can not modify the ini file, you can also run `php -d option=value` to modify ini values on the fly. You can use -d multiple times.';
  421. if (!function_exists('json_decode')) {
  422. $errors['json'] = true;
  423. }
  424. if (!extension_loaded('Phar')) {
  425. $errors['phar'] = true;
  426. }
  427. if (!extension_loaded('filter')) {
  428. $errors['filter'] = true;
  429. }
  430. if (!extension_loaded('hash')) {
  431. $errors['hash'] = true;
  432. }
  433. if (!extension_loaded('iconv') && !extension_loaded('mbstring')) {
  434. $errors['iconv_mbstring'] = true;
  435. }
  436. if (!filter_var(ini_get('allow_url_fopen'), FILTER_VALIDATE_BOOLEAN)) {
  437. $errors['allow_url_fopen'] = true;
  438. }
  439. if (extension_loaded('ionCube Loader') && ioncube_loader_iversion() < 40009) {
  440. $errors['ioncube'] = ioncube_loader_version();
  441. }
  442. if (PHP_VERSION_ID < 50302) {
  443. $errors['php'] = PHP_VERSION;
  444. }
  445. if (!isset($errors['php']) && PHP_VERSION_ID < 50304) {
  446. $warnings['php'] = PHP_VERSION;
  447. }
  448. if (!extension_loaded('openssl')) {
  449. $errors['openssl'] = true;
  450. }
  451. if (extension_loaded('openssl') && OPENSSL_VERSION_NUMBER < 0x1000100f) {
  452. $warnings['openssl_version'] = true;
  453. }
  454. if (!defined('HHVM_VERSION') && !extension_loaded('apcu') && filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN)) {
  455. $warnings['apc_cli'] = true;
  456. }
  457. if (!extension_loaded('zlib')) {
  458. $warnings['zlib'] = true;
  459. }
  460. ob_start();
  461. phpinfo(INFO_GENERAL);
  462. $phpinfo = ob_get_clean();
  463. if (preg_match('{Configure Command(?: *</td><td class="v">| *=> *)(.*?)(?:</td>|$)}m', $phpinfo, $match)) {
  464. $configure = $match[1];
  465. if (false !== strpos($configure, '--enable-sigchild')) {
  466. $warnings['sigchild'] = true;
  467. }
  468. if (false !== strpos($configure, '--with-curlwrappers')) {
  469. $warnings['curlwrappers'] = true;
  470. }
  471. }
  472. if (filter_var(ini_get('xdebug.profiler_enabled'), FILTER_VALIDATE_BOOLEAN)) {
  473. $warnings['xdebug_profile'] = true;
  474. } elseif (extension_loaded('xdebug')) {
  475. $warnings['xdebug_loaded'] = true;
  476. }
  477. if (!empty($errors)) {
  478. foreach ($errors as $error => $current) {
  479. switch ($error) {
  480. case 'json':
  481. $text = PHP_EOL."The json extension is missing.".PHP_EOL;
  482. $text .= "Install it or recompile php without --disable-json";
  483. break;
  484. case 'phar':
  485. $text = PHP_EOL."The phar extension is missing.".PHP_EOL;
  486. $text .= "Install it or recompile php without --disable-phar";
  487. break;
  488. case 'filter':
  489. $text = PHP_EOL."The filter extension is missing.".PHP_EOL;
  490. $text .= "Install it or recompile php without --disable-filter";
  491. break;
  492. case 'hash':
  493. $text = PHP_EOL."The hash extension is missing.".PHP_EOL;
  494. $text .= "Install it or recompile php without --disable-hash";
  495. break;
  496. case 'iconv_mbstring':
  497. $text = PHP_EOL."The iconv OR mbstring extension is required and both are missing.".PHP_EOL;
  498. $text .= "Install either of them or recompile php without --disable-iconv";
  499. break;
  500. case 'php':
  501. $text = PHP_EOL."Your PHP ({$current}) is too old, you must upgrade to PHP 5.3.2 or higher.";
  502. break;
  503. case 'allow_url_fopen':
  504. $text = PHP_EOL."The allow_url_fopen setting is incorrect.".PHP_EOL;
  505. $text .= "Add the following to the end of your `php.ini`:".PHP_EOL;
  506. $text .= " allow_url_fopen = On";
  507. $displayIniMessage = true;
  508. break;
  509. case 'ioncube':
  510. $text = PHP_EOL."Your ionCube Loader extension ($current) is incompatible with Phar files.".PHP_EOL;
  511. $text .= "Upgrade to ionCube 4.0.9 or higher or remove this line (path may be different) from your `php.ini` to disable it:".PHP_EOL;
  512. $text .= " zend_extension = /usr/lib/php5/20090626+lfs/ioncube_loader_lin_5.3.so";
  513. $displayIniMessage = true;
  514. break;
  515. case 'openssl':
  516. $text = PHP_EOL."The openssl extension is missing, which means that secure HTTPS transfers are impossible.".PHP_EOL;
  517. $text .= "If possible you should enable it or recompile php with --with-openssl";
  518. break;
  519. }
  520. $out($text, 'error');
  521. }
  522. $output .= PHP_EOL;
  523. }
  524. if (!empty($warnings)) {
  525. foreach ($warnings as $warning => $current) {
  526. switch ($warning) {
  527. case 'apc_cli':
  528. $text = "The apc.enable_cli setting is incorrect.".PHP_EOL;
  529. $text .= "Add the following to the end of your `php.ini`:".PHP_EOL;
  530. $text .= " apc.enable_cli = Off";
  531. $displayIniMessage = true;
  532. break;
  533. case 'zlib':
  534. $text = 'The zlib extension is not loaded, this can slow down Composer a lot.'.PHP_EOL;
  535. $text .= 'If possible, enable it or recompile php with --with-zlib'.PHP_EOL;
  536. $displayIniMessage = true;
  537. break;
  538. case 'sigchild':
  539. $text = "PHP was compiled with --enable-sigchild which can cause issues on some platforms.".PHP_EOL;
  540. $text .= "Recompile it without this flag if possible, see also:".PHP_EOL;
  541. $text .= " https://bugs.php.net/bug.php?id=22999";
  542. break;
  543. case 'curlwrappers':
  544. $text = "PHP was compiled with --with-curlwrappers which will cause issues with HTTP authentication and GitHub.".PHP_EOL;
  545. $text .= " Recompile it without this flag if possible";
  546. break;
  547. case 'php':
  548. $text = "Your PHP ({$current}) is quite old, upgrading to PHP 5.3.4 or higher is recommended.".PHP_EOL;
  549. $text .= " Composer works with 5.3.2+ for most people, but there might be edge case issues.";
  550. break;
  551. case 'openssl_version':
  552. // Attempt to parse version number out, fallback to whole string value.
  553. $opensslVersion = strstr(trim(strstr(OPENSSL_VERSION_TEXT, ' ')), ' ', true);
  554. $opensslVersion = $opensslVersion ?: OPENSSL_VERSION_TEXT;
  555. $text = "The OpenSSL library ({$opensslVersion}) used by PHP does not support TLSv1.2 or TLSv1.1.".PHP_EOL;
  556. $text .= "If possible you should upgrade OpenSSL to version 1.0.1 or above.";
  557. break;
  558. case 'xdebug_loaded':
  559. $text = "The xdebug extension is loaded, this can slow down Composer a little.".PHP_EOL;
  560. $text .= " Disabling it when using Composer is recommended.";
  561. break;
  562. case 'xdebug_profile':
  563. $text = "The xdebug.profiler_enabled setting is enabled, this can slow down Composer a lot.".PHP_EOL;
  564. $text .= "Add the following to the end of your `php.ini` to disable it:".PHP_EOL;
  565. $text .= " xdebug.profiler_enabled = 0";
  566. $displayIniMessage = true;
  567. break;
  568. }
  569. $out($text, 'comment');
  570. }
  571. }
  572. if ($displayIniMessage) {
  573. $out($iniMessage, 'comment');
  574. }
  575. return !$warnings && !$errors ? true : $output;
  576. }
  577. /**
  578. * Check if allow_url_fopen is ON
  579. *
  580. * @return true|string
  581. */
  582. private function checkConnectivity()
  583. {
  584. if (!ini_get('allow_url_fopen')) {
  585. $result = '<info>Skipped because allow_url_fopen is missing.</info>';
  586. return $result;
  587. }
  588. return true;
  589. }
  590. }