7

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

If anyone has any other suggestion that would offer a similar solution of running the php script without affecting apache or the webserver, that'sgreat too.

Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
xlordvader
  • 118
  • 1
  • 8

3 Answers3

6

skip the shell script and use

* * * * * /usr/bin/nice -n 10 /path/php -q /path/script.php

nice and\or php path may or may not be required

  • I do wish to add additional commands to the script as well. I have to run a couple more php scripts and empty a few sql tables before I run any php. – xlordvader Jan 17 '13 at 03:26
2

I'm sorry I asked this question in two places as I thought I wasn't getting a response. I asked at Superuser and I received an answer that suits my needs.

@Dagon - The answer from Dagon would seem to work as well and I will provide an update when I have resolved this issue with either solutions.

The same Question asked at Superuser - https://superuser.com/questions/537509 ...

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 more commands to run additional php scripts with the same nice property to them. They all worked great.

THANKS EVERYONE FOR THE INPUT

Community
  • 1
  • 1
xlordvader
  • 118
  • 1
  • 8
0

Either way is fine. If you put the nice in the Cron job itself, it will affect the priority of the entire job; but since the script only contains one command whose priority it really makes sense to set, doing it inside the script works just as well in practice.

tripleee
  • 175,061
  • 34
  • 275
  • 318