用php进行svn更新代码,支持断点续传0+
42,897 views / 2009.11.21 / 5:05 下午
本空间用的虚拟主机特别恶心,ftp不好用,又不支持ssh, php的安全级别又设置的比较高,导致杜工每次更新代码都特别费劲。琢磨了半天,想出了一个办法,就是直接从svn下载代码到服务器,这样就可以更新wordpress了。
<?php @set_time_limit(0); // $svnurl = "http://core.svn.wordpress.org/trunk/"; $svnurl = "http://svn.automattic.com/wordpress/trunk/"; $nowversion = file_get_contents("version.txt"); $basedir = "../71j/"; $c = preg_replace("[\r\n]", "", file_get_contents($svnurl)); $v = preg_match("/Revision\s*([0-9]+)/", $c, $m); if ($m[1] <= $nowversion) { echo "You have the latest version!"; } else { getdir(); } file_put_contents("version.txt", $m[1]); function getdir($pos = "") { global $svnurl, $basedir; $log = explode("\n", file_get_contents("log.txt")); array_pop($log); $c = file_get_contents($svnurl . $pos); preg_match_all("/<li><a\s+href=\".+?\">(.+?)<\/a><\/li>/i", $c, $m); foreach($m[1] as $n) { if ($n == "..") continue; if (strpos($n, ".") !== false) { if (!in_array($basedir . $pos . $n, $log) || end($log) == $basedir . $pos . $n) { !file_exists($basedir . $pos) && mkdir($basedir . $pos, 0777, true); file_put_contents($basedir . $pos . $n, file_get_contents($svnurl . $pos . $n)); file_put_contents("log.txt", $basedir . $pos . $n . "\n", FILE_APPEND); } } else { getdir($pos . $n); } } } > |
使用前要在本文件目录下放一个version.txt,记录svn版本号,同时要清空log.txt,因为这个记录断点续用的。
代码比较简陋,可以根据自己需要加以改进。
本站内容受著作权法保护。个人 blog 转载时请遵循 “署名-非商业用途-保持一致” 的创作共用协议;商业网站或未授权媒体不得复制本站内容。