I receive a json with data from URL (this is celery's flower plugin). Sample:
{
"celery@s1": {
"scheduled": [],
"stats": {
"clock": "2535550",
"pid": 26002,
"broker": {
"transport_options": {},
"login_method": "AMQPLAIN",
"hostname": "127.0.0.1",
"alternates": []
},
"prefetch_count": 8,
"total": {
"stone": 2602,
"wood": 34
}...
I try to parse it and make custom statistics page using PHP and JS.
Parsing with php:
<?php
$url = 'http://127.0.0.1:5555/api/workers';
$content = file_get_contents($url);
$json = json_decode($content, true);
foreach($json['celery@s1']['stats']['total'] as $item) {
echo json_encode($item['wood']);
}
?>
And JS which gets data from php script with an update timer:
function getFromFile() {
$.get("s_updater.php",function(response) {
response = JSON.parse(response);
console.log(response)
$("#field-1").html(response);
});
}
$(document).ready(function() {
var period = 1000;
getFromFile();
var per = setInterval(function() {
getFromFile();
}, period);
});
But looks that I made a mistake somewhere and now I'm stuck. And is there maybe any better way to do this? All I want is to get "wood":34 from URL's json and show value on a html page.