且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Ant在后台运行PHP脚本

更新时间:2023-09-15 16:16:58

由于你没有得到很多答案,我会建议可能让你启动一个低科技的方法...

As you're not getting many answers I'll suggest a low tech method that might get you start...

使用一个ant的exec任务来火了4后台PHP进程编写他们的pid到一个文件,其中包括内部版本号(从环境presumably)来识别它。

Use an ant exec task to fire off 4 background php processes writing their pid to a file which includes the build number (from environment presumably) to identify it.

在构建完成后运行脚本再次止损参数,并使用该文件命名系统查找进程ID,杀采取删除piddling文件。也许值得你有某种陈旧的工作中有太多的清洁剂。

Once build is complete run script again with a stop parameter and use the file naming system to find process ids, kill take and delete piddling files. Probably worth you having some sort of stale job cleaner in there too.

应该不会太硬敲了一些作品,直到你可以找到一个更好的解决方案。

Shouldn't be too hard to knock up something that works until you can find a more elegant solution.

这是任何对你有好处的:

Is this any good for you:

test.php的:(这将是你的工人脚本)

test.php: (this would be your worker script)

<?php while (true) { echo "Hello world" . PHP_EOL; sleep(5); }

runner.sh:

#!/usr/bin/bash

FILE_TO_RUN=test.php

if [ -z $TEST_RUNNERS ]; then
  TEST_RUNNERS=4;
fi;

if [ -z $BUILD_NUMBER ]; then
  echo "Can not run without a build number";
  exit 1;
fi;

FILE="${BUILD_NUMBER}.run"

if [ -e $FILE ]; then
    while read line;
    do
        echo "Killing process " $line
        kill -9 $line
    done
    echo "Deleting PID file"
    rm -f $FILE
    exit 0
fi  < $FILE

for ((i=1; i<=$TEST_RUNNERS; i++)); do
  echo "Setting up test runner number " $i " of " $TEST_RUNNERS;
  php $FILE_TO_RUN &
  echo "PID number: " $!
  echo $! >> "${BUILD_NUMBER}.run"
done
exit 0