Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have done some research on the net regarding the problem. My questions is NOT how to reduce cpu utilization by improving algorithm or improving the performance by using multitasking or limiting CPU per system user.

I have a website where user logs in does some processing and logout. The site uses linux server, php and apache. The problem is that I cant control the amount of CPU allocated to each user. ie I want give a guarantee that a user will get say atleast 5% of CPU (assume total number of users is less than 20). How can I do this?

Any solution (A php code, apache server settings, or any out of box soln) is welcomed.

Thankyou very much for reading this :)

share|improve this question
What distro/OS are you using? – Matthew Ife Jun 20 '12 at 20:38
@Mife I am using Ubuntu with bitnami LAMP stack. I can use any distro if that would help – knightrider Jun 21 '12 at 7:57

If you use PHP as CGI or FCGI application you could use cpulimit to limit cputime for the PHP process.

share|improve this answer
But this will limit the entire PHP utilization. This is not what I need – knightrider Jun 20 '12 at 19:05
You must use separate PHP processes per user to do this. The OS controls the scheduler, and PHP is an inappropriate language for doing process scheduling. Therefore breaking each user into a separate process and using cputime is a solution where you can continue to use PHP and modify the scheduler's behavior. – Robert Jun 20 '12 at 22:05

You should calculate how much cpu each of your scripts do then store it a database and for everytime a user calls for your php script it keeps adding to the database with their ID saved for later use.

Here is a quick example

$start = microtime(true); 
// Your script here
$end = microtime(true); 

Then set a cpu limit checker at the start of your php script that querys the database for the current user cpu use. If their cpu usage is higher or equal of what they are allowed then display something else instead.

share|improve this answer
Thank you for the reply. I dont want to limit the application. ie even if the time is greater than a limit, I want it to be completed. The real problem is I want to give fairness to all users not to limit them – knightrider Jun 20 '12 at 20:08
You can't be 'fair to all users' without imposing a limit at some level. – EightBitTony Jun 20 '12 at 22:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.