RavatSinh Sisodiya
RavatSinh Sisodiya

Reputation: 1608

How can I execute a PHP file using the Ant script with php output in console, while executing file

My ant script

<target name="testRunPHP">
    <exec executable="${php}" failonerror="true" dir="${source}">
            <arg line="${local.deploydir}/application/controllers/sleepTest.php"/>
            <arg line="-output" />
    </exec>
</target>

My sleepTest.php

header( 'Content-type: text/html; charset=utf-8' );
header("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
set_time_limit(0);
apache_setenv('no-gzip', 1);
ini_set('zlib.output_compression', 0);
ini_set('implicit_flush', 1);
for ($i = 0; $i < 10; $i++) { 
    $randSlp=rand(1,3);
    echo "Sleeping for ".$randSlp." second. ";;
    sleep($randSlp);
    if(ob_get_level()>0)
       ob_end_flush(); 
}
ob_implicit_flush(1);

if run file In Browser than display output while executing file
but in ant script display output (in console) after execution completed.
I want to display echo in console while file in process...

Upvotes: 0

Views: 2745

Answers (1)

pepuch
pepuch

Reputation: 6516

Exec outputs each line to stdout. The problem in your php script is thta you output this to one line. All you need to do is to add '\n' at the end of echo "Sleeping for ".$randSlp." second. \n";. I've tested this with those scripts:

build.xml

<project name="exectest" default="test">

    <dirname property="build.dir" file="${ant.file}" />

    <target name="test">

            <exec executable="cmd">
                <arg value="/c" />
                <arg value="C:\wamp\bin\php\php5.3.13\php.exe" />
                <arg value="${build.dir}\test.php" />
            </exec>

    </target>

</project>

test.php

<?php

header( 'Content-type: text/html; charset=utf-8' );
header("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
set_time_limit(0);
apache_setenv('no-gzip', 1);
ini_set('zlib.output_compression', 0);
ini_set('implicit_flush', 1);
for ($i = 0; $i < 10; $i++) { 
    $randSlp=rand(1,3);
    echo "Sleeping for ".$randSlp." second. \n";
    sleep($randSlp);
    if(ob_get_level()>0)
       ob_end_flush(); 
}
ob_implicit_flush(1);

?>

Upvotes: 3

Related Questions