使用Ant在后台运行PHP脚本 [英] Running PHP script in background using Ant

查看:132
本文介绍了使用Ant在后台运行PHP脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我现在的老板,我们使用Ant来执行我们的构建脚本,我需要添加一个目标我们的build.xml文件,将启动是在后台的Gearman工人4 PHP脚本,然后停止这些脚本一次构建完成。

At my current employer we use Ant to execute our build scripts, and I need to add a target to our build.xml file that will start up 4 PHP scripts that are Gearman workers in the background, and then stop those scripts once the build is done.

我看了'水货'和'守护'指令(是正确的字?),但我没有足够的经验与Ant来追查我缺少的信息如何确保运行脚本在后台。

I've looked at the 'parallel' and 'daemons' directives (is that the right word?) but I am not experienced enough with Ant to track down the info I'm missing on how to make sure the script runs in the background.

推荐答案

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

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

这篇关于使用Ant在后台运行PHP脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆