66 lines
1.8 KiB
PHP
66 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
use GuzzleHttp\Client as HTTPClient;
|
|
|
|
class WpContentsClient
|
|
{
|
|
//http://localhost:5101/wp
|
|
|
|
public static function serviceGetBlogItems($apiEndpointsUrl)
|
|
{
|
|
$cache = \Config\Services::cache();
|
|
|
|
if (!$cache->get('BlogWebData')){
|
|
$client = new HTTPClient();
|
|
|
|
try {
|
|
$response = $client->request(
|
|
'GET',
|
|
"http://10.0.0.52:5102/merms/wp",
|
|
['connect_timeout' => 2, 'timeout' => 3, 'debug' => false]
|
|
);
|
|
} catch (Exception $e) {
|
|
// echo "\n".$e->getMessage()."\n";
|
|
$response= []; // empty array
|
|
}
|
|
$responseArray = json_decode($response->getBody());
|
|
$cache->save('BlogWebData',$responseArray,7200);
|
|
}
|
|
else{
|
|
$responseArray = $cache->get('BlogWebData');
|
|
}
|
|
//var_dump($responseArray);
|
|
return $responseArray;
|
|
}
|
|
|
|
public static function serviceGetBlogItems2($apiEndpointsUrl)
|
|
{
|
|
$cache = \Config\Services::cache();
|
|
|
|
if (!$cache->get('BlogWebData')){
|
|
$client = new HTTPClient();
|
|
|
|
try {
|
|
$response = $client->request(
|
|
'GET',
|
|
"{$apiEndpointsUrl}/wordpress-data",
|
|
['connect_timeout' => 2, 'timeout' => 3, 'debug' => false]
|
|
);
|
|
} catch (Exception $e) {
|
|
// echo "\n".$e->getMessage()."\n";
|
|
$response= []; // empty array
|
|
}
|
|
$responseArray = json_decode($response->getBody());
|
|
$cache->save('BlogWebData',$responseArray,7200);
|
|
}
|
|
else{
|
|
$responseArray = $cache->get('BlogWebData');
|
|
}
|
|
//var_dump($responseArray);
|
|
return $responseArray;
|
|
}
|
|
}
|
|
|
|
|