Home > Backend Development > PHP Tutorial > 自己写的php curl库实现整站克隆功能_PHP

自己写的php curl库实现整站克隆功能_PHP

WBOY
Release: 2016-05-31 13:17:09
Original
777 people have browsed it

有时候经常会用到一些在线手册,比如国内或国外的,有些是访问速度慢,有些是作者直接吧网站关闭了,有些是服务器总是宕机,所以还是全盘克隆到自己服务器比较爽。

库特点:

给定一初始连接,初始链接以下的层级所有文件会拷贝到本地。
多次克隆可以配置是否覆盖。
可以配置是否下载图片。
所有链接替换为相对链接,所以可以随便rewrite。
绝对不会出现文件覆盖等问题。
最NB的特点是,没有比这更NB的库了。

SVN:http://svn.phpdr.net/repos/ares/php/library/trunk/lib/CurlMulti/MyCurl/Clone.php

下载:http://xiazai.bitsCN.com/201502/other/CurlMulti.rar

克隆结果展示(这个克隆操作几秒钟就完成了):

克隆源网站:http://www.laruence.com/manual/
克隆结果:http://manual.phpdr.net/yaf/

Demo代码:

代码如下:


class Controller_Spider extends MyYaf_Controller_Base{
 function init(){
  parent::init();
  if(!$this->getRequest()->isCli()){
      Ares_Http::error403();
  }
  include 'CurlMulti/CurlMulti.php';
  include 'CurlMulti/MyCurl.php';
  include 'phpQuery.php';
 }
}

代码如下:


class YafdocController extends Controller_Spider {
 function init() {
  parent::init ();
  include 'CurlMulti/MyCurl/Clone.php';
 }
 function indexAction() {
  $url = 'http://www.laruence.com/manual';
  $dir = Yaf_Application::app ()->getAppDirectory () . '/data/manual';
  $cacheDir = $this->getBaseDir () . '/cache/curl';
  if (! is_dir ( $cacheDir )) {
   mkdir ( $cacheDir );
  }
  $curl = new CurlMulti ();
  $curl->maxThread = 10;
  $curl->cache ['enable'] = true;
  $curl->cache ['enableDownload'] = true;
  $curl->cache ['dir'] = $cacheDir;
  $curl->cache ['compress'] = true;
  $clone = new MyCurl_Clone ( $curl, $url, $dir );
  $clone->overwrite = true;
  $clone->start ();
  return false;
 }
}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template