$val) { if ($val) { $wval .= '/'.$val; } if (!file_exists($local_dir.$wval.'/index.html')) { $commands[] = "$wget_path $wget_options $source_address$wval/"; } } } // Get the page and it's related assets if (!isset($wval)) { $commands[] = "$wget_path $wget_options $source_address$remote_request"; } // Rename all files that have a ? (query string) in their file name to not have the query string in their file name // (Whenever I can get away with it, I only use query strings to force cache busting when I make code updates) // (I tie cache busting query strings to the latest git commit hash so browsers can still utilize cache when there's been no change) // -cmin (created less than a minute ago) // -n (don't overwrite existing files) $commands[] = 'find . -name \'*\?*\' | while read filename; do mv -n "${filename}" "`echo "${filename}" | sed -e \'s/\?.*//\'`"; done'; // Remove all left over files that have a ? (query string) in their file name // -cmin (created less than a minute ago) $commands[] = 'find . -name \'*\?*\' | while read filename; do rm -f "${filename}"; done'; // Replace some strings in all files (if necessary) // -cmin (created less than a minute ago) // -exec sed (call sed and do the regex replace in-place) //$commands[] = 'find . -type f -name "index.html" -exec sed -i "s|/some.sourceserver.net|/some.publicfacingsite.com|g" {} \;'; // Remove the display dir since it's symlinked to the git dir anyway $commands[] = 'rm -rf display'; // Set the timestamps to the 1st of the current month before copying the content to the $local_dir // this helps establish a consistent etag between servers in the cluster // Don't forget to set "FileETag MTime Size" in your virtualhost if you're hosting your site off multiple servers! // (inodes for identical files will almost always be different between servers and it's included in the etag by default) date_default_timezone_set('America/Los_Angeles'); $commands[] = 'find . -type f -exec touch -d "'.date('n').'/1/'.date('Y').' 0:00" {} \;'; // Copy the contents of the $tmp_dir to the $local_dir // -r (recursive) // -u (update: only overwrite files that are newer than existing or where files don't already exist) $commands[] = "cp -ru --preserve=timestamps $tmp_dir/* $local_dir"; $commands[] = "cp -r --preserve=timestamps $tmp_dir/* $backup_dir"; $commands[] = "rm -rf $tmp_dir"; // Find any files that are older than 31 days and update their modified time to be the first of the current month $commands[] = 'cd '.$local_dir.' && find . -type f -mtime +31 -exec touch -d "'.date('n').'/1/'.date('Y').' 0:00" {} \;'; foreach ($commands as $command) { `$commands_prefix && $command`; } //print_r($commands); foreach ($output as $out) { if (preg_match('/Content-Type:/i',$out)) { header($out); } } $output = file_get_contents($local_dir.$remote_request.(substr($remote_request, -1) != '/'?'/':'').'index.html'); echo $output;