Why DomPDF (PHP 7.3.5.) generates all PDF from a list?

Hello. Here's the deal: get a list of links to wiki articles, like this
https://ru.wikipedia.org/wiki/Узел_сети
https://ru.wikipedia.org/wiki/Устройство
https://ru.wikipedia.org/wiki/Клиент-сервер
https://ru.wikipedia.org/wiki/Интерфейс
https://ru.wikipedia.org/wiki/Компьютер
https://ru.wikipedia.org/wiki/Сервер_(apparatnaya...
https://ru.wikipedia.org/wiki/Локальная_сеть
https://ru.wikipedia.org/wiki/Глобальная_сеть
https://ru.wikipedia.org/wiki/Компьютерная_сеть
https://ru.wikipedia.org/wiki/Протокол_передачи_данных
https://ru.wikipedia.org/wiki/USB


On it with POM. dompdf get PDF files. But the file's last article (USB) does not generate.

Shows error:
Notice: Undefined variable: title in /opt/lampp/htdocs/wikipdf.ru/index.php on line 82
Notice: Undefined variable: title in /opt/lampp/htdocs/wikipdf.ru/index.php on line 85
Notice: Undefined variable: title in /opt/lampp/htdocs/wikipdf.ru/index.php on line 82
Notice: Undefined variable: title in /opt/lampp/htdocs/wikipdf.ru/index.php on line 85
Notice: Undefined variable: title in /opt/lampp/htdocs/wikipdf.ru/index.php on line 82
Notice: Undefined variable: title in /opt/lampp/htdocs/wikipdf.ru/index.php on line 85
Notice: Undefined variable: title in /opt/lampp/htdocs/wikipdf.ru/index.php on line 82
Notice: Undefined variable: title in /opt/lampp/htdocs/wikipdf.ru/index.php on line 85
Notice: Undefined variable: title in /opt/lampp/htdocs/wikipdf.ru/index.php on line 82
Notice: Undefined variable: title in /opt/lampp/htdocs/wikipdf.ru/index.php on line 85
Notice: Undefined variable: title in /opt/lampp/htdocs/wikipdf.ru/index.php on line 82
Notice: Undefined variable: title in /opt/lampp/htdocs/wikipdf.ru/index.php on line 85

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 327680 bytes) in /opt/lampp/htdocs/wikipdf.ru/dompdf/lib/Cpdf.php on line 2602


The text of the program:
<?php
error_reporting(E_ALL);
require_once 'dompdf/autoload.inc.php';

use Dompdf\Dompdf;
use Dompdf\Options;

$html = ";

//get the initial page's html to grab the needed links
$url = 'https://ru.wikipedia.org/wiki/Хост';
$htmlBasic = file_get_contents($url); 

$dom = new DOMDocument();
$dom->loadHTML($htmlBasic);

//get all a-tags from div.mw-body-content
$links = [];
$xPath = new DOMXPath($dom);
$anchorTags = $xPath->evaluate("//div[@class=\"mw-body-content\"]//a/@href");

//create an array[] of links needed to iterate trhough and to create PDF files from
foreach ($anchorTags as $anchorTag) {

 //if link is not already in the array: 
 if ( !in_array($anchorTag->nodeValue, $links) ) {
 $links[] = $anchorTag->nodeValue; 
 } 
}

//handle the links for more usability
//get rid of garbage
foreach($links as $link) {

 //decode url to cyrillic
 $linkDecoded = urldecode($link);

 //if the url contains garbage, delete 
 if ( (strpos($linkDecoded, 'Category') === false) && (strpos($linkDecoded, 'Wikipedia') === false) && 
 (strpos($linkDecoded, 'index.php') === false) && (strpos($linkDecoded, 'File') === false) && 
 (strpos($linkDecoded, '#') === false) && (strpos($linkDecoded, 'English') === false) && 
 (strpos($linkDecoded, 'value') === false) ) {

 //add 'https://ru.wikipedia.org' if needed
 if ($linkDecoded[0] === '/') {
 $fullLink = trim('https://ru.wikipedia.org' . $linkDecoded);

 //PDF file title
 $title = substr($fullLink, strpos($fullLink, 'wiki/') +5); 

 echo $fullLink . '<br>';

 //get the html of every article from array[]
 $html = file_get_contents($fullLink);
}
}

 //creating PDFs
 try {
 $options = new Options();
 $options->set('defaultFont', 'DejaVu Sans'); 
 $dompdf = new Dompdf($options);

 //an alleged workout to get images into pdf
 //according to https://github.com/dompdf/dompdf/wiki/Usage
 $context = stream_context_create([ 
 'ssl' => [ 
 'verify_peer' => FALSE, 
 'verify_peer_name' => FALSE,
 'allow_self_signed'=> TRUE 
 ] 
]);
$dompdf->setHttpContext($context);

 //handle $html of an article
$dompdf->loadHtml($html);
 $dompdf->setPaper('A4', 'landscape');
$dompdf->render($title);

 $output = $dompdf->output();
 file_put_contents("/opt/lampp/htdocs/wikipdf.EN/$title.pdf", $output);

 //delete variable 
unset($dompdf);

 } catch (Exception $e) { echo 'exception Thrown: ', $e->getMessage(), "\n"; } 
}
April 4th 20 at 13:18
0 answer

Find more questions by tags PHP