Php 如何缓存JSON请求URL

Php 如何缓存JSON请求URL,php,json,caching,Php,Json,Caching,试图缓存请求URL,但没有希望 下面是我的JSON请求。我想在服务器端缓存JSON结果1小时 将JSON数据存储在PHP服务器上的.JSON文件中 缓存结果,或者至少将其保存在会话中,以便在每次页面加载时不会重复 <?php $json=file_get_contents("http://feeds.mse.mk/service/FreeMSEFeeds.svc/ticker/JSON/8BA941D0-D6E6-44BD-8D8B-47FDB7A563FA"); $dat

试图缓存请求URL,但没有希望

下面是我的JSON请求。我想在服务器端缓存JSON结果1小时

将JSON数据存储在PHP服务器上的.JSON文件中

缓存结果,或者至少将其保存在会话中,以便在每次页面加载时不会重复

<?php
    $json=file_get_contents("http://feeds.mse.mk/service/FreeMSEFeeds.svc/ticker/JSON/8BA941D0-D6E6-44BD-8D8B-47FDB7A563FA");
    $data =  json_decode($json);

    if (count($data->GetTickerJSONResult)) {
        // Open the table
        echo "<table>";

        // Cycle through the array
        foreach ($data->GetTickerJSONResult as $idx => $GetTickerJSONResult) {

            // Output a row
    $avgPerChangeValue = floatval($GetTickerJSONResult->AvgPerChange);
    $symbolName = $GetTickerJSONResult->Symbol ;

    $hrefLink = "";

    switch ($symbolName) {
        case "ALK":
            $hrefLink = "https://www.mse.mk/mk/issuer/alkaloid-ad-skopje";
            break;
        case "GRNT":
             $hrefLink = "https://www.mse.mk/mk/issuer/granit-ad-skopje"  ;
            break;
        case "KMB":
            $hrefLink = "https://www.mse.mk/mk/issuer/komercijalna-banka-ad-skopje"  ;
            break;
        case "MPT":
            $hrefLink = "https://www.mse.mk/mk/issuer/makpetrol-ad-skopje"  ;
            break;
        case "MTUR":
            $hrefLink = "https://www.mse.mk/mk/issuer/makedonijaturist-ad-skopje"  ;
            break;
        case "SBT":
            $hrefLink = "https://www.mse.mk/mk/issuer/stopanska-banka-ad-bitola"  ;
            break;
        case "TEL":
            $hrefLink = "https://www.mse.mk/mk/issuer/makedonski-telekom-ad-%E2%80%93-skopje"  ;
            break;
        case "TNB":
            $hrefLink = "https://www.mse.mk/mk/issuer/nlb-banka-ad-skopje"  ;
            break;
        case "TTK":
            $hrefLink = "https://www.mse.mk/mk/issuer/ttk-banka-ad-skopje"  ;
            break;
        default:
            echo "Does not supported symbol";
    }

    if ($avgPerChangeValue > 0 ) {

            echo "<tr>" ;
            echo "<td class='bold-green'>" . "<a href='" . $hrefLink . "'>" . $GetTickerJSONResult->Symbol . "</a></td>";
            echo "<td class='bold-green'>$GetTickerJSONResult->AvgPrice</td>";
            echo "<td class='bold-green'>$GetTickerJSONResult->AvgPerChange</td>";
            echo "</tr>";
    } else if ($avgPerChangeValue < 0 ){
            echo "<td class='bold-red'>" . "<a href='" . $hrefLink . "'>" . $GetTickerJSONResult->Symbol . "</a></td>";
            echo "<td class='bold-red'>$GetTickerJSONResult->AvgPrice</td>";
            echo "<td class='bold-red'>$GetTickerJSONResult->AvgPerChange</td>";
            echo "</tr>";
    } else {
        echo "<td class='bold-blue'>" . "<a href='" . $hrefLink . "'>" . $GetTickerJSONResult->Symbol . "</a></td>";
        echo "<td class='bold-blue'>$GetTickerJSONResult->AvgPrice</td>";
        echo "<td class='bold-blue'>$GetTickerJSONResult->AvgPerChange</td>";
        echo "</tr>";
    }


        }

        // Close the table
        echo "</table>";
    }

    echo "<style type='text/css'> td.bold-red { color: red; font-weight: bold; } td.bold-green { color: green; font-weight: bold; }  td.bold-blue { color: blue; font-weight: bold; } </style>"

?>

试试这个,在会话中存储所有json,然后使用另一个页面

session_start(); 
$json=file_get_contents("http://feeds.mse.mk/service/FreeMSEFeeds.svc/ticker/JSON/8BA941D0-D6E6-44BD-8D8B-47FDB7A563FA");
$_SESSION['data']=$json;

我没有看到任何努力/研究。太宽了。我们不是免费的编码服务。另外,我建议设置一个查找数组,其中包含与hreflink的最后部分相关联的symbolname键。