Skip to content

Commit

Permalink
textarea with generated values with copy button
Browse files Browse the repository at this point in the history
  • Loading branch information
AysadKozanoglu committed Dec 13, 2023
1 parent e63f7af commit 664b9d8
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 2 deletions.
86 changes: 86 additions & 0 deletions 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@

//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.');
}

10 changes: 9 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<title>PHP-FPM Process Caluculator</title>
<meta name="description" content="">
<meta name="author" content="Chris Moore">
<meta name="author" content="Aysad Kozanoglu">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/rangeslider.js/2.3.0/rangeslider.min.css" />
Expand Down Expand Up @@ -85,6 +86,13 @@ <h4 class="card-title mt-2">PHP-FPM Process Calculator</h4>
</div>

</form>
<form name="form1" method="post" name="coptypaste" id="copypaste">
<div class="form-group">
<label for="settingsPoolsPhp">php pool settings / tuning</label>
<textarea class="form-control" name="copyPasteArea" id="copyPasteArea" rows="4"></textarea>
<button name="buttonCopy" id="buttonCopy" onClick="copyClipboard()" type="button" class="btn btn-success">Copy to Clipboard</button>
</div>
</form>
</div>
</div>
</div>
Expand All @@ -96,4 +104,4 @@ <h4 class="card-title mt-2">PHP-FPM Process Calculator</h4>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rangeslider.js/2.3.0/rangeslider.min.js"></script>
<script src="script.js"></script>
</body>
</html>
</html>
24 changes: 23 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ $(document).ready(function() {
$("#ram-total, #ram-reserved, #ram-buffer, #process-size").on("keydown keyup change", function() {
sum();
});
generateConfigCopy();

$("buttonCopy").click(function(){
copyClipboard
});

});

function sum() {
Expand Down Expand Up @@ -61,4 +67,20 @@ function sum() {
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.');
}

0 comments on commit 664b9d8

Please sign in to comment.