File_exists()和过期缓存不符合逻辑


file_exists() and expired cache not following logic

逻辑上我试图找出为什么我的代码不工作。

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';
}

我总是以回显"不存在"的结果结束。

我的第一个观察可能是解决方案,你有:

  if(file_exists('templates/cache/' . $persona['toolbar_id'] . 'txt')){

你没有在txt前漏掉一个点吗?我认为应该是:

 if(file_exists('templates/cache/' . $persona['toolbar_id'] . '.txt')){

在其他方法中,例如:

 file_put_contents('templates/cache/' . $persona['toolbar_id']. '.txt', $result);

你有。txt:)