I stumbled upon the situation where I have a functional test that puts a job in a queue and tests the result of it being processed.
But in testing environment I don’t want the queue consumer to be permanently running, so the test would need to start the queue consumer, wait until it does its thing, and later stop it.
The problem is that when doing something like:
// ... `php queue:consumer:start --env=test &` // ... `php queue:consumer:stop --env=test &` // ...
the queue would start but the test script would be suspended, waiting for the start command to finish, never reaching the following instructions nor the stop command.
So after some google-fu I ended up finding the solution is to do this:
// ... pclose(popen("php queue:consumer:start --env=test &", "r")); // ... `php queue:consumer:stop --env=test &` // ...