dongzhao4036
2012-03-27 01:54
浏览 235
已采纳

如何在Mac中同时执行PHP CLI脚本

I have 50 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 script file that would execute all 50 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.

I am new to both MAC and Scripting - maybe I don't need a script? Is there another mac based solultion that can do this without me having to open 50 separate terminal windows?

图片转代码服务由CSDN问答提供 功能建议

我有50个php文件,我想从命令行同时运行。 现在,我使用代码在多个CLI窗口中运行它们:

php Script1.php

我希望能够调用一个 单个脚本文件,可同时执行所有50个php文件。 我一直在阅读如何使命令行不等待输出,但我似乎无法使其工作。

我是MAC和脚本的新手 - 也许我 不需要脚本? 是否有另外一个基于mac的解决方案可以做到这一点,而我不必打开50个独立的终端窗口?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • duanshanduo3363 2012-03-27 02:00
    已采纳

    You can just add ampersand '&' to separate each command:

    php script1.php & php script2.php & php script3.php ...
    

    This ampersand symbol will tell the shell to run command on background.

    To check the output, you can redirect it to a file:

    php script1.php > script1.log.txt & php script2.php > script2.log.txt
    

    And you can just do a tail on it to read the log:

    tail -f script1.log.txt
    
    点赞 打赏 评论
  • duanhuan2301 2012-03-27 02:27

    If you script is nicely numbered from 1 to 50, you can try the following in a .command file:

    i=1;
    while [ $i -lt 51 ]
    do
    osascript -e 'tell app "Terminal"
        do script "php Script$i.php"
    end tell' &
    i=$[$i+1]
    done
    

    This should open 50 separate terminal windows each running script{$i}.php

    点赞 打赏 评论
  • duanlu1950 2012-03-27 02:30

    You could also run them at the same time but not in the background.

    php test1.php; php test2.php;
    

    I don't know why you would want to "interact" with the script after its running.

    点赞 打赏 评论

相关推荐 更多相似问题