2

I have 3 scripts that do some stuff. I want to run them continously and concurrently.

Let's say for example: First script took 30 minutes to finish. Second - 20 mins. Third - 5 mins.

So I need everyone of them to run immediately after it's finished. The 3 scripts make UPDATE in a same DB, but they need to work separately. They can run together at once, but not couple of times(my english sucks, sorry about that). Let's explain what I mean with example:

firstScript.php is running
secondScript.php is running
thirdScript.php is running

firstScript.php trying to start but it still running. Wait.(till finish)

May be some shell script will do the job, but how?

4
  • Are all three scripts accessible by urls? The only thing I could think of is to create one cron script that curls sequentially to them and waits for a response before proceeding to the next when run, but this is a very ugly solution. Consider this - could these scripts be run by user traffic elsewhere in your site, using their request to make remote calls? The nature of php as Request-to-run makes it difficult to leverage for tasks like this. Commented Nov 22, 2011 at 22:44
  • Nope. They're not accessible by urls. I need to run them manually. Commented Nov 22, 2011 at 23:23
  • Is it an option to save state to disk? I can think of a few approaches that would save a paging file of what is running and when ran, load the file first and determine what to do from there. Commented Nov 22, 2011 at 23:32
  • I think it'll be easier with the method bellow. Just "tell" at the end of the script that I need to execute it again. But thanks for your help and time. I really appreciate it! Commented Nov 22, 2011 at 23:57

2 Answers 2

3

Make a bash script that takes one argument, and have it do something like this:

if [ -f /tmp/$1 ]
then
    echo "Script already running"
else
    touch /tmp/$1
    php $1
    rm /tmp/$1
fi

Set up a cron to run this script and pass it the name of the php script you want to run.

Sign up to request clarification or add additional context in comments.

Comments

0

You could execute a shell command just before the php script dies. Example :

while($i < 1000)
{
$i++;
}
shell_exec("bin/php.exe some_script.php");

If you are working on a shared hosting account this might not work do to security issues. note the "bin/php.exe" need to be edited for your server, point to where ever your php is installed.

1 Comment

Hmm.. It's just freeze for few seconds with this one and doesn't run the script again. Safe mode is off and I'm using VPS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.