1

I'm trying to write a cronjob which launches multiple processes that I want to run in parallel.

I'm using a foreach calling each command, but the command line waits for the output. I don't want it to put.

Was wondering if anyone ever used any library for this?

2 Answers 2

1

Add an ampersand after the command:

$ php task.php &

It will run that instance of php in the background and continue.

Sign up to request clarification or add additional context in comments.

1 Comment

Note this only works on unix based systems use "start /B" + command, to do it on a windows server.
0

If you read the manual on passthru you'll notice it tells you how to avoid this...

If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.

So you can rely on UNIX fds to redirect output to something like /dev/null for example if you don't care about the output or to some file if you do want to save the output and this will avoid PHP waiting on the command to finish.

pssthru("somecommand > /some/path/to/file")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.