Skip to content

Instantly share code, notes, and snippets.

@mdunham
Created March 26, 2018 10:29
Show Gist options
  • Save mdunham/e77e2aff7ab515323062c7794b04c70c to your computer and use it in GitHub Desktop.
Save mdunham/e77e2aff7ab515323062c7794b04c70c to your computer and use it in GitHub Desktop.
This will allow you to easily change all of the PHP FPM Pool settings for all the domains you have running it on the WHM MultiPHP Manager.
/**
* To use just login to your WHM and go to MultiPHP Manager.
* This is where all FPM pool options are defined. Just copy the code below
* and paste it into your browsers dev tools console.
*
* To change the FPM Pool confs after you've pasted the code into your console and pressed enter to run it.
* You can then tell it to change the confs here is the code to execute the process:
*
* Documentation: window.setFpmPools('[MAX CLIENTS]', '[IDEL TIMEOUT]', '[MAX REQUESTS]');
* Real Example: window.setFpmPools( '5' , '15' , '100' );
*
* Just paste that into your dev tools console and press enter to start the updates.
*/
(function(app){
window.setFpmPools = app;
})(function(maxC, timeO, maxR, ran){
var
selLimit = document.querySelector('#pageSize_select'),
sortByDom = document.querySelector('a.sort-link[sort-field="vhost"]'),
selMax = selLimit.querySelector('option[label="All"]').value,
setPools = function() {
var buttons = [], table = document.getElementById('accountList');
[].map.call(table.querySelectorAll('button[id^="php_fpm_pool_button"]'), function(btn){
buttons.push(btn);
});
function nextBtn() {
if ( ! buttons.length) return ( ! ran ) ?
(ran = setTimeout(setPools, 3000)) && console.log('Verifing that all pools are updated') : console.log('All Pools Updated Successfully');
var button = buttons.shift();
button.dispatchEvent(new Event('click'));
setTimeout(() => { stepTwo(button.parentNode.parentNode); }, 150);
}
function stepTwo(parent) {
var
formArea = (parent && parent.querySelector(':scope div.row.pool_options')) || false,
maxChilds = (formArea && formArea.querySelector(':scope input[name="maxChildren"]')) || false,
timeOut = (formArea && formArea.querySelector(':scope input[name="idelTimeout"]')) || false,
maxReqs = (formArea && formArea.querySelector(':scope input[name="maxRequests"]')) || false,
saveBtn = (formArea && formArea.querySelector(':scope button.btn-primary')) || false,
vHostNm = (parent && parent.parentNode.querySelector('td[data-title="Domain"]').innerText) || false;
if (formArea && maxChilds && timeOut && maxReqs && saveBtn && (maxC !== maxChilds.value || maxR !== maxReqs.value || timeO !== timeOut.value)) {
console.log('\nUpdating ' + vHostNm.trim() + '\'s Pool\nMax Clients: ' + maxChilds.value + ' -> ' + maxC
+ '\t Idle Timeout: ' + timeOut.value + ' -> ' + timeO + '\t Max Requests: '
+ maxReqs.value + ' -> ' + maxR + '\n');
maxChilds.value = maxC;
maxChilds.dispatchEvent(new Event('change'));
timeOut.value = timeO;
timeOut.dispatchEvent(new Event('change'));
maxReqs.value = maxR;
maxReqs.dispatchEvent(new Event('change'));
setTimeout(() => { saveBtn.dispatchEvent(new Event('click')) }, 150);
} else {
if (vHostNm) console.log( ( ! ran) ? 'No change needed skipping ' + vHostNm.trim() : vHostNm.trim() + ' update confirmed!');
return nextBtn();
}
setTimeout(nextBtn, 1000);
}
sortByDom.dispatchEvent(new Event('click'));
setTimeout(nextBtn, 2500);
};
console.log('Updating All FPM Pools\n------------\nMax Clients: ' + maxC
+ '\nIdle Timeout: ' + timeO + '\nMax Requests: ' + maxR
+ '\n------------\n');
if (parseInt(maxC) < 2 || parseInt(maxC) > 30)
return console.log('Error - Max Clients must be between 2 and 30');
if (parseInt(timeO) < 2 || parseInt(timeO) > 90)
return console.log('Error - Idle Timeout must be between 2 and 90');
if (parseInt(maxR) < 2 || parseInt(maxR) > 500)
return console.log('Error - Max Requests must be between 2 and 500');
if ( ! selLimit) return console.log('Error - Couldn\'t find the show amount select element. Are you on the MultiPHP page?');
selLimit.value = selMax;
selLimit.dispatchEvent(new Event('change'));
setTimeout(() => { sortByDom.dispatchEvent(new Event('click')) }, 1500);
setTimeout(setPools, 3000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment