Using several threads can potentially increase the speed of your overall execution time, but it can also potentially make what you're trying to achieve much more complicated, so it should generally be avoided unless the speed improvements are really worth it to you.
In addition, if this is being triggered (as I suspect) by someone loading a webpage, then it is almost certainly a bad plan to use threading. This is discussed in better detail here. If it's being triggered from the command line such as:
php processTextFile.php
Then it could potentially be something that may benefit you.
As to whether in this particular instance it will speed up your processing, that will depend on what exactly you're doing.
From how you word your problem, you could be trying to do 2 things:
Running a pipeline of tasks on a text file. In this context, the data that you receive after running the first task on it would be different from the initial data, then you would be running this new data through the second task. (For example, perhaps you have a JSON encoded object and the first task is decoding it into an array). If you're doing this, then multithreading will not help you as each thread needs the data it will need to use from when you initialise the thread.
Doing your separate tasks all on the original file and then returning the processed data to be return your results. In this instance, multithreading would work.
If multithreading is still valid for your use case, then:
- You can run the 30 scripts in parallel. You would tend to see a performance increase only on boxes where you have either multiple processors or multiple cores as it would allow the computer to use both at the same time
- You can use pthread to achieve this (95% sure, this thread supports that view)
- To work out how to actually use it you might want to look at the examples on the GitHub project of the implementation