abdul202 Posted April 19, 2013 Share Posted April 19, 2013 hello, i have a php script that use alot of cpu i have asked here before about away to limit the cpu usage for a spacific user here it's the thread url http://forums.phpfreaks.com/topic/277008-how-to-limit-the-cpu-usage-for-a-script/ as trq pointed me for using the NICE http://linux.die.net/man/1/nice to set priorties my question is .... is that possible to Add nice option to 'exec' command??? i have a command like that exec ('' . $php_path . ' -c ' . $config_ini . ' mirrors/rapidshare.php ' . $file_uid . ' ' . $status . ' >/dev/null &'); if it's possible.. how can i do that? best regards Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 19, 2013 Share Posted April 19, 2013 Yes, you can add a nice option to exec command, but why are you using php to do this? Anyway, before do this make sure what permissions has apache to the nice folder. Then create a string like: <?php $nice = 'which nice'; // find where is a nice command in your system $str = "$php_path . ' -c ' . $config_ini . ' mirrors/rapidshare.php ' . $file_uid . ' ' . $status.';'"; $str .="$nice n 5 u $user"; exec($str); // or with a shell_exec() shell_exec($str); Quote Link to comment Share on other sites More sharing options...
abdul202 Posted April 20, 2013 Author Share Posted April 20, 2013 Yes, you can add a nice option to exec command, but why are you using php to do this? Anyway, before do this make sure what permissions has apache to the nice folder. Then create a string like: <?php $nice = 'which nice'; // find where is a nice command in your system $str = "$php_path . ' -c ' . $config_ini . ' mirrors/rapidshare.php ' . $file_uid . ' ' . $status.';'"; $str .="$nice n 5 u $user"; exec($str); // or with a shell_exec() shell_exec($str); thank you for your help , i'm using php to do that because it's a php script used to convert videos using ffmped extension anyway your code it looks good but i don't understand the $user refer to what maybe you mean the website user or you mean something else and also you need to replace the single quote $nice = 'which nice'; to $nice = "which nice"; i didn't haven't tested that code yet but i'll update you when i do best regards Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 23, 2013 Share Posted April 23, 2013 Is it a dedicated or shared server? P.S: Yes, my fault, the " -u" flag is available only for a renice unix command. There is no problem using single quotes here. Quote Link to comment Share on other sites More sharing options...
Joshua F Posted April 24, 2013 Share Posted April 24, 2013 (edited) $nice = 'which nice';to $nice = "which nice";i didn't haven't tested that code yet but i'll update you when i do best regards Actually, it's common practice to use single quotes if you're not putting any 'code' into them. (EG. $string = 'world'; echo "hello {$string}, how are you?"; echo "hello $string, how are you?";) A bit off-topic but I wanted to point that out. Edited April 24, 2013 by Joshua F Quote Link to comment Share on other sites More sharing options...
abdul202 Posted April 30, 2013 Author Share Posted April 30, 2013 it's a dedicated server centos 5.9 best regards Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.