コード例 #1
0
ファイル: Cst.php プロジェクト: paullarrow/CDN-Sync-Tool
 public function syncManyFiles()
 {
     global $wpdb;
     $arrDebug = array();
     $strDebugPath = ABSPATH . '/wp-content/cache/debug_cst2.txt';
     touch($strDebugPath);
     $strCachePath = wdgPathCheck(ABSPATH . '/wp-content/cache');
     $strCachePath = wdgPathCheck(ABSPATH . '/wp-content/cache/cdn');
     $strFilesToSyncPath = wdgFileCheck($strCachePath . '/filetosync.cdn_sync');
     $strProgressPath = wdgFileCheck($strCachePath . '/progress.cdn_sync');
     $strCountPath = wdgFileCheck($strCachePath . '/progress_count.cdn_sync');
     $arrResults = unserialize(file_get_contents($strFilesToSyncPath));
     if (!empty($arrResults)) {
         $this->createConnection();
         $t1 = getmicrotime();
         $arrDebug['createConnection'] = getmicrotime() - $t1;
         file_put_contents($strCountPath, count($arrResults));
         for ($x = 0; $x < 8 && !empty($arrResults); $x++) {
             $file = array_shift($arrResults);
             // file_put_contents($strProgressPath, 'Beginning pushFile call: '.$file['remote_path'].'<br />', FILE_APPEND);
             $t1 = getmicrotime();
             if (file_exists($file['file_dir'])) {
                 try {
                     $this->pushFile($file['file_dir'], $file['remote_path']);
                 } catch (Exception $e) {
                     echo 'File could not be uploaded: DB not updated. ';
                     return false;
                 }
             }
             $arrDebug['pushFile'] = getmicrotime() - $t1;
             // file_put_contents($strProgressPath, 'Syncing complete. ', FILE_APPEND);
             $resUpdate = $wpdb->update(CST_TABLE_FILES, array('synced' => '1'), array('id' => $file['id']));
             // file_put_contents($strProgressPath, 'DB records updated! <br /><hr />', FILE_APPEND);
             file_put_contents($strCountPath, count($arrResults));
             file_put_contents($strFilesToSyncPath, serialize($arrResults));
             file_put_contents($strDebugPath, print_r($arrDebug, true));
         }
     }
     return true;
 }
コード例 #2
0
function cst_sync_progress()
{
    $strCachePath = wdgPathCheck(ABSPATH . '/wp-content/cache');
    $strCachePath = wdgPathCheck(ABSPATH . '/wp-content/cache/cdn');
    $strFilesToSyncPath = wdgFileCheck($strCachePath . '/filetosync.cdn_sync');
    $strProgressPath = wdgFileCheck($strCachePath . '/progress.cdn_sync');
    $strProgress = file_get_contents($strProgressPath);
    file_put_contents($strProgressPath, '');
    $arrResults = unserialize(file_get_contents($strFilesToSyncPath));
    echo json_encode(array('remaining' => sizeof($arrResults), 'progress_message' => $strProgress));
    die;
}