-
Notifications
You must be signed in to change notification settings - Fork 23
/
other-utilities.php
90 lines (73 loc) · 1.5 KB
/
other-utilities.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* Logic for certain utilities that do not
* belong elsewhere.
*
* @package Automattic/vip-go-ci
*/
declare(strict_types=1);
/**
* Get version of PHP interpreter specified.
*
* @param string $php_path Path to PHP binary to get version for.
*
* @return string|null PHP version number, null on failure.
*/
function vipgoci_util_php_interpreter_get_version(
string $php_path
) :string|null {
$cache_id = array( __FUNCTION__, $php_path );
$cached_data = vipgoci_cache( $cache_id );
if ( false !== $cached_data ) {
return $cached_data;
}
$php_cmd = sprintf(
'%s %s',
escapeshellcmd( $php_path ),
escapeshellarg( '-v' )
);
$php_output_2 = '';
$php_result_code = -255;
$php_output = vipgoci_runtime_measure_exec_with_retry(
$php_cmd,
array( 0 ),
$php_output_2,
$php_result_code,
'php_cli',
false
);
if ( null === $php_output ) {
vipgoci_sysexit(
'Unable to get PHP version due to error',
array(
'cmd' => $php_cmd,
'output' => $php_output,
),
VIPGOCI_EXIT_SYSTEM_PROBLEM
);
}
$php_output = str_replace(
'PHP ',
'',
$php_output
);
$php_output_arr = explode(
' ',
$php_output
);
// If something went wrong, return null.
if ( empty( $php_output_arr[0] ) ) {
return null;
}
$php_version_str = trim( $php_output_arr[0] );
vipgoci_log(
'Determined PHP version',
array(
'php-path' => $php_path,
'php-version' => $php_version_str,
),
2
);
vipgoci_cache( $cache_id, $php_version_str );
return $php_version_str;
}