I have a php script that I need to run on shared webhosting.
I have created a cron job that executes an sh script. The command in my crontab is:
/bin/sh /home/user/script.sh
I'm assuming it is Bourne Shell (or something compatible). The script itself is:
#!/bin/sh
cd /home/user/public_html/folder/
#updating DB
php -q ./run_interactive_job.php batch_control_files/updateDB
echo Updated DB results
I have following questions:
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 the above command 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 for unblock it to test it with different parameters. And now I'm trying to run it through cron at a lower priority – hoping 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. All of them worked fine.
THANKS EVERYONE FOR THE INPUT @sm4rk0 answer solves my problems
Best Answer
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 withman nice
I found that example in question had wrong syntax. The right syntax would be: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.