update Piwik to version 2.16 (fixes #91)
This commit is contained in:
parent
296343bf3b
commit
d885a4baa9
5833 changed files with 418860 additions and 226988 deletions
101
www/analytics/core/CliMulti/CliPhp.php
Normal file
101
www/analytics/core/CliMulti/CliPhp.php
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
namespace Piwik\CliMulti;
|
||||
|
||||
use Piwik\Common;
|
||||
|
||||
class CliPhp
|
||||
{
|
||||
|
||||
public function findPhpBinary()
|
||||
{
|
||||
if (defined('PHP_BINARY')) {
|
||||
if ($this->isHhvmBinary(PHP_BINARY)) {
|
||||
return PHP_BINARY . ' --php';
|
||||
}
|
||||
|
||||
if ($this->isValidPhpType(PHP_BINARY)) {
|
||||
return PHP_BINARY . ' -q';
|
||||
}
|
||||
}
|
||||
|
||||
$bin = '';
|
||||
|
||||
if (!empty($_SERVER['_']) && Common::isPhpCliMode()) {
|
||||
$bin = $this->getPhpCommandIfValid($_SERVER['_']);
|
||||
}
|
||||
|
||||
if (empty($bin) && !empty($_SERVER['argv'][0]) && Common::isPhpCliMode()) {
|
||||
$bin = $this->getPhpCommandIfValid($_SERVER['argv'][0]);
|
||||
}
|
||||
|
||||
if (!$this->isValidPhpType($bin)) {
|
||||
$bin = shell_exec('which php');
|
||||
}
|
||||
|
||||
if (!$this->isValidPhpType($bin)) {
|
||||
$bin = shell_exec('which php5');
|
||||
}
|
||||
|
||||
if (!$this->isValidPhpType($bin)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$bin = trim($bin);
|
||||
|
||||
if (!$this->isValidPhpVersion($bin)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$bin .= ' -q';
|
||||
|
||||
return $bin;
|
||||
}
|
||||
|
||||
private function isHhvmBinary($bin)
|
||||
{
|
||||
return false !== strpos($bin, 'hhvm');
|
||||
}
|
||||
|
||||
private function isValidPhpVersion($bin)
|
||||
{
|
||||
global $piwik_minimumPHPVersion;
|
||||
$cliVersion = $this->getPhpVersion($bin);
|
||||
$isCliVersionValid = version_compare($piwik_minimumPHPVersion, $cliVersion) <= 0;
|
||||
return $isCliVersionValid;
|
||||
}
|
||||
|
||||
private function isValidPhpType($path)
|
||||
{
|
||||
return !empty($path)
|
||||
&& false === strpos($path, 'fpm')
|
||||
&& false === strpos($path, 'cgi')
|
||||
&& false === strpos($path, 'phpunit');
|
||||
}
|
||||
|
||||
private function getPhpCommandIfValid($path)
|
||||
{
|
||||
if (!empty($path) && is_executable($path)) {
|
||||
if (0 === strpos($path, PHP_BINDIR) && $this->isValidPhpType($path)) {
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $bin PHP binary
|
||||
* @return string
|
||||
*/
|
||||
private function getPhpVersion($bin)
|
||||
{
|
||||
$command = sprintf("%s -r 'echo phpversion();'", $bin);
|
||||
$version = shell_exec($command);
|
||||
return $version;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue