-
Notifications
You must be signed in to change notification settings - Fork 46
/
1
86 lines (67 loc) · 2.84 KB
/
1
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
//range slider
var $element = $('input[type="range"]');
$element
.rangeslider({
polyfill: false,
onInit: function() {
var $handle = $('.rangeslider__handle', this.$range);
updateHandle($handle[0], this.value);
}
})
.on('input', function(e) {
var $handle = $('.rangeslider__handle', e.target.nextSibling);
updateHandle($handle[0], this.value);
});
function updateHandle(el, val) {
el.textContent = val;
}
//calculator
$(document).ready(function() {
//calculate values automatically
sum();
$("#ram-total, #ram-reserved, #ram-buffer, #process-size").on("keydown keyup change", function() {
sum();
});
generateConfigCopy();
$("buttonCopy").click(function(){
copyClipboard
});
});
function sum() {
//inputs
var ramtotal = document.getElementById('ram-total').value;
var ramreserved = document.getElementById('ram-reserved').value;
var rambuffer = document.getElementById('ram-buffer').value;
var processsize = document.getElementById('process-size').value;
var buffer = 1 - (rambuffer / 100) ;
//[Total Available RAM] – [Reserved RAM] – [10% buffer] = [Available RAM for PHP]
var availableram = Math.round(((ramtotal - ramreserved) * buffer) * 10) / 10;
var availablerammb = Math.round(availableram * 1024);
// [Average Process Size] / [Available RAM for PHP]= [max_children]
var maxchildren = Math.floor(availablerammb / processsize);
var startservers = Math.floor(maxchildren * 0.25);
var minspare = Math.floor(maxchildren * 0.25);
var maxspare = Math.floor(maxchildren * 0.75);
if (!isNaN(availableram)) {
//Outputs
//document.getElementById('ram-buffer-percent').value = buffer;
document.getElementById('ram-available').value = availableram;
document.getElementById('ram-available-mb').value = Math.round(availableram * 1024);
document.getElementById('max-children').value = maxchildren;
document.getElementById('start-servers').value = startservers;
document.getElementById('min-spare').value = minspare;
document.getElementById('max-spare').value = maxspare;
}
}
function generateConfigCopy (){
document.getElementById('copyPasteArea').value = 'pm.max_children = ' + document.getElementById('max-children').value +'\n'
+ 'pm.start_servers = ' + document.getElementById('start-servers').value +'\n'
+ 'pm.min_spare_servers = ' + document.getElementById('min-spare').value +'\n'
+ 'pm.max_spare_servers = ' + document.getElementById('max-spare').value;
}
function copyClipboard (){
var text = document.getElementById('copyPasteArea');
text.select();
document.execCommand('copy');
alert('copied to clipboard successfully.');
}