Getting the status of http GET requests after video ingestion using PUT

Here's my requirement. I'm little bit new to PHP.

I'm ingesting video files to a server using http PUT. I have put them in a loop with 1 minute gap using PHP file_get_contents method.I can get the status of ingesting video file using http GET request .So what i need is continuously monitor the status while ingesting video files.

1 1st PUT request, Then Start getting status using GET with 10 second gap ,

After 1 minute

2.2nd PUT request Starts

Start getting status of 2nd file & continue getting the status of 1 st file until status change to complete

Here's my code:

<?php

$fp = fopen('ingesttest1.csv', 'wb');
$dir = '/home/mit/NSK/XML/';

function GetReply($urln,$bodyn) {

    $opts2 = array('http'=>array('method'=>"GET",'timeout' => 30, 'content' => 
    $bodyn));
    $context2 = stream_context_create($opts2);
    $categoryResOrg2 = @file_get_contents($urln, false, $context2); // send
    $response = simplexml_load_string($categoryResOrg2);
    $state= $response->ContentDetail->DeploymentState;

    return $state;
}

if($handle = opendir($dir)) {

    while (false !== ($entry = readdir($handle))) {

        if ($entry != "." && $entry != "..") {



            $filedirectory='/home/mit/NSK/XML/'.$entry.'';

            $directry= pathinfo($entry, PATHINFO_FILENAME);

            $res = simplexml_load_file($filedirectory);

            foreach ($res->Asset->Metadata->App_Data as $appdata){

                if ($appdata->attributes()->Name == "Run_Time"){
                    $Run_Time = $appdata->attributes()->Value;
                    $dt = new DateTime("1970-01-01 $Run_Time", new 
                    DateTimeZone('UTC'));
                    $seconds = (int)$dt->getTimestamp();

                }

            }

            $url='http://192.17.1.50:7010/Content/PeoVOD/'.$directry.'';
            $body='<?xml version="1.0" encoding="utf-8"?>
            <Content xmlns="urn:test:1.0">
            <Popularity>3</Popularity>
            <DurationInSec>'.$seconds.'</DurationInSec>
            <Source>ftp://slt:XXXX/Archive/VOD/'.$directry.'/</Source>
            <ProfileName>MP4S</ProfileName>
            </Content>';



            $opts = array('http'=>array('method'=>"PUT",'timeout' => 30,   
            'content' => $body)); 

            $context = stream_context_create($opts);
            $categoryResOrg = @file_get_contents($url, false, $context); 



            sleep(2);




            $state =  GetReply($url,$body);


            $timeout = time() + 60*5;

            while($state!='eDeploymentStateFinishedFullyDeployed'){

                if($state=='eDeploymentStateFinishedFullyDeployed' || time() > $timeout){

                    break;
                }

                $state =  GetReply($url,$body);

                echo $state;
                echo $directry." is ".$state;

                sleep(5);

                $data = array($directry,$state);
                fputcsv($fp, $data);


            }

            echo ''.$directry.' completed<br>';          
        }      
    }  
}

?>