forked from AlternC/alternc-php-fpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphp7-fpm
executable file
·71 lines (58 loc) · 2.18 KB
/
php7-fpm
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
#!/usr/bin/php
<?php
/* This crontab adds/remove FPM pools for php 7.0/1/2/3
for each user who uses a fpm configuration
*/
require_once("/usr/share/alternc/panel/class/config_nochk.php");
// first launch sync_unix since we NEED unix user to exist!
passthru("/usr/lib/alternc/install.d/alternc-nss end");
$force = (isset($argv[1]) && $argv[1]=="force");
$db->query("SELECT DISTINCT m.login,m.uid,sd.type FROM sub_domaines sd, membres m WHERE m.uid=sd.compte AND sd.type IN ('php56-fpm','php70-fpm','php71-fpm','php72-fpm','php73-fpm','php74-fpm');");
$reload=array();
$allpools=array();
$allversions=array("5.6","7.0","7.1","7.2","7.3","7.4");
// detect installed versions
foreach($allversions as $k=>$version) {
if (!is_dir("/etc/php/$version/fpm/pool.d")) {
unset($allversions[$k]);
}
}
function myecho($str) {
static $first=true;
if ($first) {
echo date("Y-m-d H:i:s")." Log of php7-fpm\n";
$first=false;
}
echo $str."\n";
}
while ($db->next_record()) {
$version=substr($db->f("type"),3,1).".".substr($db->f("type"),4,1);
$user=$db->f("login");
$allpools[$version][]=$user;
if ($force || !is_file("/etc/php/".$version."/fpm/pool.d/".$user.".alternc.conf")) {
myecho("Creating php $version fpm pool for user $user");
file_put_contents("/etc/php/".$version."/fpm/pool.d/".$user.".alternc.conf",
str_replace("%%LOGIN%%",$user,
file_get_contents("/etc/alternc/templates/php/fpm-".$version)
));
$reload[$version]=$version;
}
}
// now delete pools we don't need anymore
foreach($allversions as $version) {
$d=opendir("/etc/php/$version/fpm/pool.d");
while (($c=readdir($d))!==false) {
if (preg_match('#([^\.]*).alternc.conf$#',$c,$mat)) {
$user=$mat[1];
if (!in_array($user,$allpools[$version])) {
myecho("Deleting php $version fpm pool for user $user");
@unlink("/etc/php/".$version."/fpm/pool.d/".$user.".alternc.conf");
$reload[$version]=$version;
}
}
}
}
// now reloads php fpm versions
foreach($reload as $service) {
passthru("/etc/init.d/php".$service."-fpm reload");
}