Vladi Iancu

CTO · I write about engineering leadership, systems, and staying human

Stress Test your PHP App with POST Requests

Send multiple POST requests with some JSON to test the performance of your app

dev

If you need a quick and easy way to stress test your PHP application by sending a lot of POST requests with some JSON, this post is for you.

What you will need for this:

  1. ApacheBench (official link)
  2. A file with some JSON in it

First, let's create our file.

cd stress-folder
touch data.txt
nano data.txt

Paste your JSON. It could be something simple such as {"name": "Dummy Name"}

Excellent work so far.

Now for the test command. You might be already familiar with the classic command:

ab -n 100 -c 10 "http://localhost:8080/"

In our case we would need to write

ab -p data.txt -T application/json -n 100 -c 10 http://localhost:8080/

And, if you also need to send some headers

ab -p data.txt -T application/json -H 'Header-Name: header-value' -n 100 -c 10 http://localhost:3000/

Hints:

  • if you need multiple headers sent, you simply add multiple -H flags.
  • you can also send cookies with the -C flag.
  • maybe add the -k flag to Enable KeepAlive

If you found this worth reading, share it on Bluesky or LinkedIn.