ci_depends.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #!/usr/bin/env php
  2. <?php
  3. /**
  4. * Lithium: the most rad php framework
  5. *
  6. * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
  7. * @license http://opensource.org/licenses/bsd-license.php The BSD License
  8. */
  9. if (isset($argv[1]) && 'APC' === strtoupper($argv[1])) {
  10. PhpExtensions::install('apc');
  11. } else {
  12. PhpExtensions::install('xcache');
  13. }
  14. PhpExtensions::install('mongo');
  15. /**
  16. * Class to install native PHP extensions mainly
  17. * for preparing test runs.
  18. */
  19. class PhpExtensions {
  20. /**
  21. * Holds build, configure and install instructions for PHP extensions.
  22. *
  23. * @var array Extensions to build keyed by extension name.
  24. */
  25. protected static $_extensions = array(
  26. 'memcached' => array(
  27. 'url' => 'http://pecl.php.net/get/memcached-2.0.1.tgz',
  28. 'require' => array(),
  29. 'configure' => array(),
  30. 'ini' => array(
  31. 'extension=memcached.so'
  32. )
  33. ),
  34. 'apc' => array(
  35. 'url' => 'http://pecl.php.net/get/APC-3.1.10.tgz',
  36. 'require' => array(),
  37. 'configure' => array(),
  38. 'ini' => array(
  39. 'extension=apc.so',
  40. 'apc.enabled=1',
  41. 'apc.enable_cli=1'
  42. )
  43. ),
  44. 'xcache' => array(
  45. 'url' => 'http://xcache.lighttpd.net/pub/Releases/1.3.2/xcache-1.3.2.tar.gz',
  46. 'require' => array(
  47. 'php' => array('<', '5.4')
  48. ),
  49. 'configure' => array('--enable-xcache'),
  50. 'ini' => array(
  51. 'extension=xcache.so',
  52. 'xcache.cacher=false',
  53. 'xcache.admin.enable_auth=0',
  54. 'xcache.var_size=1M'
  55. )
  56. ),
  57. 'mongo' => array(
  58. 'url' => 'http://pecl.php.net/get/mongo-1.2.7.tgz',
  59. 'require' => array(),
  60. 'configure' => array(),
  61. 'ini' => array(
  62. 'extension=mongo.so'
  63. )
  64. )
  65. );
  66. /**
  67. * Install extension by given name.
  68. *
  69. * Uses configration retrieved as per `php_ini_loaded_file()`.
  70. *
  71. * @see http://php.net/php_ini_loaded_file
  72. * @param string $name The name of the extension to install.
  73. * @return void
  74. */
  75. public static function install($name) {
  76. if (!isset(static::$_extensions[$name])) {
  77. return;
  78. }
  79. $extension = static::$_extensions[$name];
  80. echo $name;
  81. if (isset($extension['require']['php'])) {
  82. $version = $extension['require']['php'];
  83. if (!version_compare(PHP_VERSION, $version[1], $version[0])) {
  84. $message = " => not installed, requires a PHP version %s %s (%s installed)\n";
  85. printf($message, $version[0], $version[1], PHP_VERSION);
  86. return;
  87. }
  88. }
  89. static::_system(sprintf('wget %s > /dev/null 2>&1', $extension['url']));
  90. $file = basename($extension['url']);
  91. static::_system(sprintf('tar -xzf %s > /dev/null 2>&1', $file));
  92. $folder = basename($file, '.tgz');
  93. $folder = basename($folder, '.tar.gz');
  94. $message = 'sh -c "cd %s && phpize && ./configure %s ';
  95. $message .= '&& make && sudo make install" > /dev/null 2>&1';
  96. static::_system(sprintf($message, $folder, implode(' ', $extension['configure'])));
  97. foreach ($extension['ini'] as $ini) {
  98. static::_system(sprintf("echo %s >> %s", $ini, php_ini_loaded_file()));
  99. }
  100. printf("=> installed (%s)\n", $folder);
  101. }
  102. /**
  103. * Executes given command, reports and exits in case it fails.
  104. *
  105. * @param string $command The command to execute.
  106. * @return void
  107. */
  108. protected static function _system($command) {
  109. $return = 0;
  110. system($command, $return);
  111. if (0 !== $return) {
  112. printf("=> Command '%s' failed !", $command);
  113. exit($return);
  114. }
  115. }
  116. }
  117. ?>