PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 4.3.0
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v4.3.0
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / CliMulti / CliPhp.php
matomo / app / core / CliMulti Last commit date
CliPhp.php 5 years ago Output.php 5 years ago Process.php 5 years ago RequestCommand.php 5 years ago RequestParser.php 5 years ago
CliPhp.php
117 lines
1 <?php
2 /**
3 * Matomo - free/libre analytics platform
4 *
5 * @link https://matomo.org
6 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7 */
8 namespace Piwik\CliMulti;
9
10 use Piwik\Common;
11 use Piwik\Config;
12
13 class CliPhp
14 {
15
16 public function findPhpBinary()
17 {
18 $general = Config::getInstance()->General;
19 if (!empty($general['php_binary_path']) && file_exists($general['php_binary_path'])) {
20 return $general['php_binary_path'];
21 }
22
23 if (defined('PHP_BINARY')) {
24 if ($this->isHhvmBinary(PHP_BINARY)) {
25 return PHP_BINARY . ' --php';
26 }
27
28 if ($this->isValidPhpType(PHP_BINARY)) {
29 return PHP_BINARY . ' -q';
30 }
31 }
32
33 $bin = '';
34
35 if (!empty($_SERVER['_']) && Common::isPhpCliMode()) {
36 $bin = $this->getPhpCommandIfValid($_SERVER['_']);
37 }
38
39 if (empty($bin) && !empty($_SERVER['argv'][0]) && Common::isPhpCliMode()) {
40 $bin = $this->getPhpCommandIfValid($_SERVER['argv'][0]);
41 }
42
43 if (empty($bin)) {
44 $possiblePhpPath = PHP_BINDIR . ('\\' === \DIRECTORY_SEPARATOR ? '\\php.exe' : '/php');
45 $bin = $this->getPhpCommandIfValid($possiblePhpPath);
46 }
47
48 if (!$this->isValidPhpType($bin) && function_exists('shell_exec')) {
49 $bin = @shell_exec('which php');
50 }
51
52 if (!$this->isValidPhpType($bin)) {
53 return false;
54 }
55
56 $bin = trim($bin);
57
58 if (!$this->isValidPhpVersion($bin)) {
59 return false;
60 }
61
62 $bin .= ' -q';
63
64 return $bin;
65 }
66
67 private function isHhvmBinary($bin)
68 {
69 return false !== strpos($bin, 'hhvm');
70 }
71
72 private function isValidPhpVersion($bin)
73 {
74 global $piwik_minimumPHPVersion;
75 $cliVersion = $this->getPhpVersion($bin);
76 $isCliVersionValid = $cliVersion && version_compare($piwik_minimumPHPVersion, $cliVersion) <= 0;
77 return $isCliVersionValid;
78 }
79
80 private function isValidPhpType($path)
81 {
82 if (empty($path)) {
83 return false;
84 }
85 $path = basename($path);
86
87 return false === strpos($path, 'fpm')
88 && false === strpos($path, 'cgi')
89 && false === strpos($path, 'phpunit')
90 && false === strpos($path, 'lsphp');
91 }
92
93 private function getPhpCommandIfValid($path)
94 {
95 if (!empty($path) && @is_executable($path)) {
96 if (0 === strpos($path, PHP_BINDIR) && $this->isValidPhpType($path)) {
97 return $path;
98 }
99 }
100 return null;
101 }
102
103 /**
104 * @param string $bin PHP binary
105 * @return string
106 */
107 private function getPhpVersion($bin)
108 {
109 $command = sprintf("%s -r 'echo phpversion();'", $bin);
110 $version = null;
111 if (function_exists('shell_exec')) {
112 $version = @shell_exec($command);
113 }
114 return $version;
115 }
116 }
117