Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have this php script that I need to run on shared webhosting. I have created a cron job that executes an sh script. The command for the cron was:

/bin/sh /home/user/script.sh

So I'm assuming it is Bourne Shell (or something compatible). The script itself was:

#!/bin/sh
cd /home/user/public_html/folder/
#updating DB
php -q ./run_interactive_job.php batch_control_files/updateDB
echo Updated DB results

My question is:
Can I add Nice priorities to the php command ? Or do I need to add it to the script at the cron command. Which one is more likely to work ?

nice 10 php -q ./run_interactive_job.php batch_control_files/updateDB

Would that be successful at running at a lower priority.

PS: Basically, this script has overloaded the server before when I ran it through the browser and it affected apache on that server resulting in my hosts blocking the file. I have repeatedly asked them unblock to test it with different parameters. And Now I'm trying to run it through cron at a lower priority in the hopes that it won't affect apache. But I don't want it to create issues again, hence I'm trying to use NICE

UPDATE: I used the batch file as shown there. I used the nice command before php inside the batch file. The only difference being:

nice -n 10 php -q ./run_interactive_job.php batch_control_files/updateDB

I added commands to run additional php scripts with the same nice property to them. They all worked great.

THANKS EVERYONE FOR THE INPUT @sm4rk0 answer solves my problems

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Both methods should work, but IMO it's cleaner to put nice into the script just as you did in your example. After a check with man nice I found that example in question had wrong syntax. The right syntax would be:

nice -n 10 command

Nicenesses range from -20 (most favorable scheduling) to 19 (least favorable).

And, as terdon said, 10 is the default value so "-n 10" can be omitted.

Note: Although it will lower the process priority, nice won't make it cause less CPU load. So, if only reason to worry about is not to "choke" the apache, then this method is OK. But if your hosts give you some CPU time quota, this won't help a lot.

share|improve this answer
    
The tech support team repeatedly blocked it after the script ran for about 10 minutes and slowed down the server. They don't seem to have CPU quota or I am well under that considering that my website itself is not resource intensive. –  xlordvader Jan 17 '13 at 3:13
    
Is that command correct on the syntax ? I have never tried Nice nor nice with a cron in a script. And I don't want to get kicked of the server again. Pain to talk with tech –  xlordvader Jan 17 '13 at 3:24
    
Yes. The nice syntax is OK. Give it a try, then come back here to update us if it worked. –  sm4rk0 Jan 17 '13 at 3:27
    
For sure. Thanks ! –  xlordvader Jan 17 '13 at 3:27
    
I'm sorry, the syntax was not OK. Correct syntax would be: nice -n 10 command –  sm4rk0 Jan 17 '13 at 4:14

Your Answer

 
discard

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.