Jump to content

Add nice option to 'exec' command in php


abdul202

Recommended Posts

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
Share on other sites

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
Share on other sites

 

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
Share on other sites

 

$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 by Joshua F
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.