forked from rlerdorf/php7dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
newphp
executable file
·66 lines (56 loc) · 1.91 KB
/
newphp
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
#!/usr/local/php70/bin/php
<?php
$prefix = "/usr/local";
$map = [
'bin/phar'=>'bin/phar.phar',
'bin/phar.phar'=>'bin/phar.phar',
'bin/php'=>'bin/php',
'bin/php-cgi'=>'bin/php-cgi',
'bin/php-config'=>'bin/php-config',
'bin/phpize'=>'bin/phpize',
'include/php'=>'include/php',
'lib/php/build'=>'lib/php/build',
'php'=>'php',
'sbin/php-fpm'=>'sbin/php-fpm'
];
if($argc<2) usage();
$debug = $zts = false;
if($argc>2) {
if($argv[2] == 'debug') { $debug = true; $zts = false; }
else if($argv[2] == 'zts') { $debug = false; $zts = true; }
else if($argv[2] == 'debugzts') { $debug = true; $zts = true; }
}
$version = $argv[1];
if($version=='7') switch_php('php70', $debug, $zts);
else if($version=='5') switch_php('php56', $debug, $zts);
else if(file_exists("$prefix/$version/bin/php")) switch_php($version, $debug, $zts);
else switch_php('php'.$version, $debug, $zts);
function usage() {
global $argv;
$cmd = basename($argv[0]);
echo "Usage: $cmd 70|56|55|54|53|52|51 [debug/zts/debug-zts]\n";
echo "To switch to PHP 5.5-debug: tryphp 55 debug\n\n";
exit;
}
function switch_php($version, $debug=false, $zts = false) {
global $map, $prefix;
$path = "$prefix/$version";
if($debug) $path .= '-debug';
if($zts) $path .= '-zts';
if(!is_file("$path/bin/php")) {
echo "$prefix/$version/bin/php doesn't exist\n";
return false;
}
$real_version = trim(shell_exec("$prefix/$version/bin/php -v | head -1"));
echo "Activating PHP $real_version and restarting php-fpm\n";
foreach($map as $link=>$target) {
// echo "Creating $prefix/$link => $path/$target\n";
symlink_it("$path/$target", "$prefix/$link");
}
shell_exec("service php-fpm restart");
}
function symlink_it($target, $link) {
// Skip files that have been hard-linked in place
if(file_exists($link) && !is_link($link)) return false;
shell_exec("ln -f -s $target $link");
}