Generic filters
Exact matches only
  • Run tasks in parallel (using bat files)

    23rd July 2014

    Random Coding

    random coding category codehaven

    If we want to run tasks in parallel, this can be tricky.

    We want 5 files to run at the same time. If each file takes 2 seconds to run, then all of them should take 2 seconds if this is true, else it will take 10 seconds.

    Method 1

    The below example takes 10 seconds.
    testfile.php

    hitcounter.php (this one file takes 2 seconds to complete)

    Conclusion: – each file is run in series therefore this example takes 10 seconds to complete…
    (Not the answer I was looking for)

    I then wrote a script that writes to a database the time in seconds and milliseconds and run this in the same way. The results show that it takes two seconds for each file. The correct result should be all have the same second at least!

    I changed hitcounter.php to the following code.

    It runs the file and adds to the database the time it ran….great!

    Lets do two of them…

    Ok this ran but there was still a two second gap between inserts….

    Lets add a magic word….. START

    Now we have the files being run with only a very very small time difference ie 30-40 milliseconds….

    Conclusion

    Therefore if we wish to run files at the same time use a bat file with start….this does not run then wait for a file to come back to it….

    Was this code snippet helpful?