Jayela
Jayela

Reputation: 375

Run a PHP script multiple times simultaneously linux command line

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.

Upvotes: 4

Views: 2815

Answers (2)

nextstep
nextstep

Reputation: 1480

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

Upvotes: 1

JoeCodeCreations
JoeCodeCreations

Reputation: 668

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

Upvotes: 6

Related Questions