논리적으로 내 코드가 작동하지 않는 이유를 파악하려고합니다.file_exists() 및 만료 된 캐시가 논리를 따르지 않음
foreach($list as $persona){
//If file exists
if(file_exists('templates/cache/' . $persona['toolbar_id'] . 'txt')){
//file is expired older than 10 seconds for testing purposes
if(time() - filemtime('/templates/cache/' . $persona['toolbar_id'] . '.txt') >= 10) {
// jSON URL which should be requested
$json_url = 'example';
// Initializing curl
$ch = curl_init($json_url);
// Configuring curl options
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array('Content-type: application/json') ,
);
// Setting curl options
curl_setopt_array($ch, $options);
// Getting results
$result = curl_exec($ch); // Getting jSON result string
file_put_contents('templates/cache/' . $persona['toolbar_id']. '.txt', $result);
$result = json_decode($result, true);
$result = $result[0];
echo 'expired-recreating cache';
}
$result = json_decode(file_get_contents('templates/cache/' . $persona['toolbar_id']. '.txt'), true);
$result = $result[0];
}
// jSON URL which should be requested
$json_url = ''';
// Initializing curl
$ch = curl_init($json_url);
// Configuring curl options
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array('Content-type: application/json') ,
CURLOPT_POSTFIELDS => $json_string
);
// Setting curl options
curl_setopt_array($ch, $options);
// Getting results
$result = curl_exec($ch); // Getting jSON result string
file_put_contents('templates/cache/' . $persona['toolbar_id']. '.txt', $result);
$result = json_decode($result, true);
$result = $result[0];
echo 'didnt exist';
}
나는 항상 'didnt exist'라는 메시지가 출력됩니다. 여기에 도움을 주시면 대단히 감사하겠습니다. 솔루션이 될 수 있습니다
무슨 뜻 다른 더 에코없이 "존재 didnt는" ? 어떤 출구 나 휴식을 볼 수 없기 때문에 – Scuzzy
실제로 foreach() 내에 있으므로 여러 결과가 있습니다. – lockdown
그래, 방금 루프의 반복마다 논리에 관계없이 "존재하지 않는"것으로 나타났습니다. 빈 $ json_url을 사용하여 두 번째 컬 요청을 한 다음 파일을 다운로드 한 다음 시간을 확인하고 있습니까? – Scuzzy