Home  >  Article  >  Backend Development  >  The php curl library written by myself realizes the whole site cloning function, phpcurl_PHP tutorial

The php curl library written by myself realizes the whole site cloning function, phpcurl_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:07:03873browse

The php curl library written by myself realizes the whole site cloning function, phpcurl

Sometimes I often use some online manuals, such as domestic or foreign ones. Some are slow to access, some are closed by the author directly, and some are because the server is always down, so it is better to clone the entire disk to your own server. Cool.

Library Features:

Given an initial connection, all files in the hierarchy below the initial connection will be copied locally.
Multiple cloning can be configured to overwrite or not.
You can configure whether to download images.
All links are replaced with relative links, so they can be rewritten at will.
There will definitely be no problems such as file overwriting.
The most NB feature is that there is no library more NB than this.

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

Bangkejia download: http://xiazai.jb51.net/201502/other/CurlMulti.rar

Clone result display (this cloning operation is completed in a few seconds):

Clone source website: http://www.laruence.com/manual/
Clone result: http://manual.phpdr.net/yaf/

Demo code:

Copy code The code is as follows:

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

Copy code The code is as follows:

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/957129.htmlTechArticleThe php curl library I wrote myself implements the whole site cloning function. phpcurl sometimes uses some online manuals, such as Domestic or foreign, some have slow access speeds, and some are directly accessed by the author...
Statement:
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