开发者

retrieving continuous stream of xml data, decoding it and putting it in a db

I am trying to build an application that retrieves continuous streams of xml data which keeps on changing every second, then decode it and it insert it into a mysql database. So this script probably has to be executing on the server without any gui. But from the client side(from within the browser) the user should be able to start or stop the dumping process.

That is the script must be basically performing this.

 while($dump == true)
    {
    $fetchxml = "http://agent.getstream.org/sample?from=$seq";
    $seq = $fetchxml["nextsequ开发者_运维知识库ence"];
    $somedata = $fetchxml["sumdata"];
    mysqlinsert_db;
    }

so that from the browser if i click a button in the server side i should be able to recieve it andchange $dump to true or false depending upon wether start or stop is pressed.

Is this possible? technology no constraint. infact i would be glad if some one can inform me what tech i should use in the backend for a requirement like this as frontend would obviously be in javascript.


You want a process on the server to halt and restart from a different process.

One way to tell the continuous process to halt is using a lock file.

while (true) {
   if (file_exists('continue.tmp')) {
      // Do whatever is done
   } else {
     // do nothing for a minute
     sleep(60);
   }
}

The other process just throws away continue.tmp to stop the processing and creates it to resume.

A better alternative would be to exit the loop when the file is thrown away and restart the process using whatever method your server has for that - but how to do that really depends on the server used. But then by recreating the lock file in the restart you know instantly that it has started or not.


Considering this script would be runned in CLI you have 2 way to control it. I will tell you what I'd use.

while(true) {
  //> do your operations
  include('control.php');
}

When you want to stop it you just need to put an exit; in the control.php.
Of course you can inject any variables/objects if you need further controls.

For what regards the retrive part you can simply use file_get_contents and simpleXML class to handle the data

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜