4

I need to test some locking in my PHP script and need to run it many times at the same time.

I remember I found a simple command to do that some time ago when I was testing MySQL locking, but can't remember the function and can't find it again. I'm running Ubuntu Linux 14.04.1.

I'm looking for a simple command without any loops.

Thanks.

Jayela
  • 365
  • 1
  • 4
  • 7
  • I believe `&` will do the trick. Did you try `php script1.php & php script1.php & php script1.php` ? – luchosrock Jul 14 '15 at 18:14
  • the problem is i need to run it at least 50 times and later maybe 1000 times, that's why that won't work but thanks for a suggestion. – Jayela Jul 14 '15 at 18:33
  • 2
    possible duplicate of [How to make a bash script that creates 40 simultaneous instances of a program?](http://stackoverflow.com/questions/2220030/how-to-make-a-bash-script-that-creates-40-simultaneous-instances-of-a-program) – Karl Jul 14 '15 at 18:39
  • I tried using `&` to run 50 but it didn't run a most of them. – Jayela Jul 14 '15 at 18:50
  • Karl, I've seen a couple of those, but there's some simple command without any loops. – Jayela Jul 14 '15 at 18:56
  • possible duplicate of [Is there a better way to run a command N times in bash?](http://stackoverflow.com/questions/3737740/is-there-a-better-way-to-run-a-command-n-times-in-bash) – Avalanche Jul 14 '15 at 19:09
  • Avalanche, I've noted that it doesn't use loops and got the answer already, please take a look. Thanks. – Jayela Jul 14 '15 at 19:16

2 Answers2

6

Use AB testing in linux

run this command

ab -n 1000 -c 5 http://yourpage.php

where -n 1000 means 1000 times to run it

and where -c 5 means you are going to do 5 concurrent processes

if you want to automate it to happen on its own activate a curl in a cron job

45 11 * * * /usr/bin/curl -G 127.0.0.1/yourscript.php >/dev/null 2>&1

this will run it every day at 11 45 am

See this page for more details about AB testing or benchmark testing in linux

Linux Benchmarking

JoeCodeCreations
  • 660
  • 2
  • 6
  • 19
1

You can use this command to run your script multiple times:

cmd="..some command..."; for i in $(seq 5); do $cmd; sleep 1; done

For instance, this:

cmd="ls"; for i in $(seq 5); do $cmd; sleep 1; done

will list files in the current directory 5 times with one second in between.

Change the command to execute the script you need to, and change the $(seq 5) to how ever many times you want to run the command.

e.g

cmd="php my_script.php"; for i in $(seq 1000); do $cmd; sleep 1; done
nextstep
  • 1,399
  • 3
  • 11
  • 26