Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to try to stress-test a PHP script I've written, which accesses the filesystem, to see how it copes with load and parallel access.

I'd like to run this script x times in y different processes parallelly.

Is there a tool for this?

share|improve this question
echo {0..$x} | xargs -n 1 -P $y php yourscript.php might be a start – frostschutz Jul 16 '13 at 13:04
@frostschutz Excellent, thanks. Can you add this as an answer? – Benjamin Jul 16 '13 at 13:08
There is also parallel from moreutils. – derobert Jul 16 '13 at 15:44
up vote 1 down vote accepted

xargs allows easy parallel processing. Here is an example (which assumes that your version of xargs supports the -0 switch, which is not a POXIX requirement. If portability is an issue, simply use echo and drop the -0).

printf '%s\0' {1..$maxruns} | xargs -0 -I, -n 1 -P $instances <program>

printf outputs the numbers from 1 to 2000 delimited by NULL characters. This is piped to xargs. The -0 option notifies xargs that the values are delimited by a NULL characters instead of whitespace. The -I switch replaces the following character (a comma, can be any character sequence) with the input value. Since the input values are the numbers, which we don't need, and there is no other comma in the command line, the input is simply discarded. -n 1 provides a maximum of one argument to <program>. -P 50 runs no more than 50 instances of <program> at a time.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.