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 Link to comment https://forums.phpfreaks.com/topic/277145-add-nice-option-to-exec-command-in-php/ 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); Link to comment https://forums.phpfreaks.com/topic/277145-add-nice-option-to-exec-command-in-php/#findComment-1425810 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 Link to comment https://forums.phpfreaks.com/topic/277145-add-nice-option-to-exec-command-in-php/#findComment-1425948 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. Link to comment https://forums.phpfreaks.com/topic/277145-add-nice-option-to-exec-command-in-php/#findComment-1426187 Share on other sites More sharing options...
Joshua F Posted April 24, 2013 Share Posted April 24, 2013 $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. Link to comment https://forums.phpfreaks.com/topic/277145-add-nice-option-to-exec-command-in-php/#findComment-1426254 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 Link to comment https://forums.phpfreaks.com/topic/277145-add-nice-option-to-exec-command-in-php/#findComment-1427361 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.