Skip to content

Commit

Permalink
Merge pull request #13 from nadar/add-cycles-index
Browse files Browse the repository at this point in the history
add cycles info
  • Loading branch information
nadar authored Jan 13, 2021
2 parents ab8787e + a12e17e commit 0c0dc45
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).
In order to read more about upgrading and BC breaks have a look at the [UPGRADE Document](UPGRADE.md).

## 1.4.0 (13. January 2020)

+ [#13](https://github.com/nadar/crawler/pull/13) New Crawler method `getCycles()` returns the number of times the `run()` method was called.

## 1.3.0 (20. December 2020)

+ [#10](https://github.com/nadar/crawler/issues/10) Add relative url check to `Url` class.
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"description": "A highly extendible, dependency free Crawler for HTML, PDFS or any other type of Documents.",
"name": "nadar/crawler",
"type": "library",
"authors": [
Expand Down
24 changes: 12 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions src/Crawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ class Crawler
*/
protected $runner;

/**
* @var integer Contains the number of cycles where run() was called.
* @since 1.4.0
*/
protected $cycles = 0;

/**
* Constructor
*
Expand Down Expand Up @@ -173,6 +179,17 @@ public function getParsers() : array
return $this->parsers;
}

/**
* Returns the number of cycles where run() was called.
*
* @return integer
* @since 1.4.0
*/
public function getCycles()
{
return $this->cycles;
}

/**
* Get all upcoming jobs from the queue and parse them into a Job object
*
Expand Down Expand Up @@ -206,6 +223,7 @@ public function setup()
*/
public function run()
{
$this->cycles++;
$curlRequests = [];
$multiCurl = curl_multi_init();

Expand Down
5 changes: 3 additions & 2 deletions src/Handlers/DebugHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function onSetup(Crawler $crawler)
*/
public function onEnd(Crawler $crawler)
{
$this->summary();
$this->summary($crawler->getCycles());
}

/**
Expand All @@ -109,9 +109,10 @@ public function afterRun(Result $result)
/**
* Generates and prints a summary
*/
public function summary()
public function summary($cycles)
{
echo "==================" . PHP_EOL;
echo "run cycles: " . $cycles . PHP_EOL;
echo "index size: " . ($this->counter) . PHP_EOL;
echo "time: " . ($this->elapsedTime()) . PHP_EOL;
echo "memory peak: " . $this->memoryPeak() . PHP_EOL;
Expand Down

0 comments on commit 0c0dc45

Please sign in to comment.