Skip to content
This repository was archived by the owner on Jun 2, 2023. It is now read-only.

Commit 74ae89d

Browse files
author
Stefan
committed
Working PHP 8 Multiprocessing (linux)
1 parent fb6e05d commit 74ae89d

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

libs/ProcessCommunication/PHPCrawlerDocumentInfoQueue.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function addDocumentInfo(PHPCrawlerDocumentInfo $DocInfo): void
8383
$ser = serialize($DocInfo);
8484

8585
$this->PDO->exec('BEGIN EXCLUSIVE TRANSACTION');
86-
$this->preparedInsertStatement->bindParam(1, $ser, PDO::PARAM_LOB);
86+
$this->preparedInsertStatement->bindParam(1, $ser, PDO::PARAM_STR);
8787
$this->preparedInsertStatement->execute();
8888
$this->preparedSelectStatement->closeCursor();
8989
$this->PDO->exec('COMMIT');
@@ -97,7 +97,7 @@ public function getNextDocumentInfo()
9797
$this->createPreparedStatements();
9898

9999
$this->preparedSelectStatement->execute();
100-
$this->preparedSelectStatement->bindColumn('document_info', $doc_info, PDO::PARAM_LOB);
100+
$this->preparedSelectStatement->bindColumn('document_info', $doc_info, PDO::PARAM_STR);
101101
$this->preparedSelectStatement->bindColumn('id', $id);
102102
$row = $this->preparedSelectStatement->fetch(PDO::FETCH_BOUND);
103103
$this->preparedSelectStatement->closeCursor();

libs/UrlCache/PHPCrawlerURLCacheBase.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ public function addLinkPriority($regex, $level): void
131131
$this->url_priorities[$c]['level'] = trim($level);
132132

133133
// Sort url-priortie-array so that high priority-levels come firts.
134-
PHPCrawlerUtils::sort2dArray($this->url_priorities, 'level', SORT_DESC);
134+
#PHPCrawlerUtils::sort2dArray($this->url_priorities, 'level', SORT_DESC);
135+
$key_values = array_column($this->url_priorities, 'level');
136+
array_multisort($key_values, SORT_ASC, $this->url_priorities);
137+
135138
}
136139

137140
/**

libs/Utils/PHPCrawlerUtils.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -521,13 +521,15 @@ public static function sort2dArray(&$array, $sort_args): void
521521
{
522522
$args = func_get_args();
523523

524-
// F?r jedes zu sortierende Feld ein eigenes Array bilden
524+
525+
// Form a separate array for each field to be sorted
525526
foreach ($array as $fieldKey => $field) {
527+
526528
for ($x = 1, $xMax = count($args); $x < $xMax; $x++) {
527-
// Ist das Argument ein String, sprich ein Sortier-Feld?
529+
// Is the argument a string, i.e. a sort field?
530+
528531
if (is_string($args[$x])) {
529532
$value = $array[$field][$args[$x]];
530-
531533
${$args[$x]}[] = $value;
532534
}
533535
}

multiprocessing_example.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public function handleDocumentInfo($DocInfo): int
6161
echo $lb;
6262

6363
flush();
64+
return 0;
6465
}
6566
}
6667

@@ -85,7 +86,8 @@ public function handleDocumentInfo($DocInfo): int
8586
// "http://php.net/manual/en/" followed by "mysql" somewhere.
8687
// So we add a corresponding follow-rule to the crawler.
8788
$crawler->addURLFollowRule('#^http://php.net/manual/en/.*mysql[^a-z]# i');
88-
89+
$crawler->setRequestLimit(10); // Set the page-limit to 50 for testing
90+
$crawler->addLinkPriority('/php/i', 1);
8991
// That's it, start crawling using 5 processes
9092
$crawler->goMultiProcessed(5);
9193

0 commit comments

Comments
 (0)