octopoda/octopus
Composer 安装命令:
composer require octopoda/octopus
包简介
PHP Sitemap crawler
README 文档
README
Small PHP tool to crawl collections of URLs in a Sitemap using the PHPReact library for asynchronous loading of the URLs. Both plain text files and XML Sitemaps are supported.
Usage from the Command Line Interface (CLI)
Crawl the URLs in a Sitemap with verbose logging (-vvv).
php application.php http://www.domain.ext/sitemap.xml -vvv
Using 15 concurrent connections instead of the default 5 concurrent connections:
php application.php http://www.domain.ext/sitemap.xml --concurrency 15 -vvv
Use a HTTP GET request instead of the default HTTP HEAD. Note that HTTP HEAD requests involve less data transfer since no body is involved:
php application.php http://www.domain.ext/sitemap.xml --requestType GET -vvv
Use a timeout of 3 seconds instead of the default 10 seconds:
php application.php http://www.domain.ext/sitemap.xml --timeout 3 -vvv
Use a specific UserAgent instead of the default Octopus/1.0, for example, to simulate a search engine crawling a sitemap:
php application.php http://www.domain.ext/sitemap.xml --userAgent 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)' -vvv
Use the TablePresenter to display intermediate results instead of the default EchoPresenter:
php application.php http://www.domain.ext/sitemap.xml --presenter Octopus\\Presenter\\TablePresenter -vvv
Usage from your own application
You can easily integrate sitemap crawling in your own application, have a look at the Config class for all possible configuration options. If required you can use a PSR3-Logger for logging purposes.
use Octopus\Config; use Octopus\Processor; $config = new Config(); $config->concurrency = 2; $config->targetFile = 'https://www.domain.ext/sitemap.xml'; $config->additionalResponseHeadersToCount = array( 'CF-Cache-Status', //Useful to check CloudFlare edge server cache status ); $config->requestHeaders = array( 'User-Agent' => 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', //Simulate Google's webcrawler ); $processor = new Processor($config, $this->logger); //A PSR3 Logger can be injected if required $processor->run(); $this->logger->info('Statistics: ' . print_r($processor->result->getStatusCodes(), true)); $this->logger->info('Applied concurrency: ' . $config->concurrency); $this->logger->info('Total amount of processed data: ' . $processor->result->getTotalData()); $this->logger->info('Failed to load #URLs: ' . count($processor->result->getBrokenUrls()));
Limitations
Currently, Octopus is mainly an experimental / educational tool. Advanced use cases in HTTP response handling might not be supported.
Tests
To run the test suite, you first need to clone this repository and then install all dependencies using Composer:
$ composer install
To run the test suite, go to the project root and run:
$ make test
octopoda/octopus 适用场景与选型建议
octopoda/octopus 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.9k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2017 年 12 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 octopoda/octopus 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 octopoda/octopus 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4.9k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-12-06
