简体   繁体   中英

How to feed live json onto php

I have a web server url that generating json data. Data is refreshed every 5 sec. It looks like this:

[{"key": 0, "value": 586},{"key": 1, "value": 509},{"key": 2, "value": 472},{"key": 3, "value": 458},{"key": 4, "value": 454},{"key": 5, "value": 436}]

I am able to display it in php like this:

1.

 <?php
        $url = 'http://16x.xxx.xxx.2xx:8180';
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $data = curl_exec($ch);
        curl_close($ch);
        echo $data;
        ?>

Question, is how do I auto update this to capture all the values every 5 sec?

  1. I am also trying to write to a mysql table.

You can write a script that you run from the command line (CLI) with nohup that will read your data every X seconds and process it according to your needs.

example : nohup php /my/php/script.php &

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM