Executing multiple simultaneous php scripts from CLI

…衆ロ難τιáo~ 提交于 2019-12-10 15:24:28

问题


I have 55 php files that I would like to run simultaneously from the command line. Right now, I am running them in multiple CLI windows using the code:

php Script1.php

I would like to be able to call one single php file that would execute all 55 php files simultaneously. I have been reading about how to make the command line not wait for the output, but I can't seem to make it work.

This thread: How to run multiple PHP scripts from CLI

suggests putting an & at the end of the command to run the command in the background, but using the xampp CLI this doesn't seem to do anything.

Any ideas greatly appreciated.

Brian


回答1:


By mentioning XAMPP, I assume you are on windows. I think what you need is the start command. You probably need start php Script1.php. For more info, do a

start /?|more



回答2:


Linux

Apart from adding a &, you also need to redirect output to somewhere - otherwise your php process waits until the other process finished, because there could be more output:

exec('/path/to/program & > /dev/null 2>&1')



回答3:


You could use the php forking mechanism. Read about it here: http://php.net/manual/en/function.pcntl-fork.php



来源:https://stackoverflow.com/questions/6577802/executing-multiple-simultaneous-php-scripts-from-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!