{"id":471637,"date":"2025-08-22T15:01:11","date_gmt":"2025-08-22T15:01:11","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=471637"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=471637","title":{"rendered":"<span>\u041b\u0435\u043d\u0438\u0432\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0432 PHP: \u043a\u0430\u043a \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0438 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u044d\u043a\u043e\u043d\u043e\u043c\u044f\u0442 \u043f\u0430\u043c\u044f\u0442\u044c \u0438 \u0443\u0441\u043a\u043e\u0440\u044f\u044e\u0442 \u043a\u043e\u0434<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u044b \u043a\u043e\u0433\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u044b\u0442\u0430\u043b\u0438\u0441\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0432 \u043f\u0430\u043c\u044f\u0442\u044c CSV-\u0444\u0430\u0439\u043b \u043d\u0430 <strong>\u043c\u0438\u043b\u043b\u0438\u043e\u043d \u0441\u0442\u0440\u043e\u043a<\/strong> \u0438 \u0443\u0432\u0438\u0434\u0435\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435:<\/p>\n<pre><code class=\"php\">PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted<\/code><\/pre>\n<p>\u0414\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c <code>memory_limit<\/code>, \u043e\u0449\u0443\u0449\u0435\u043d\u0438\u0435 \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u043e\u0435: \u043c\u044b \u0434\u0435\u0440\u0436\u0438\u043c \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432\u0435\u0441\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u0434\u0430\u043d\u043d\u044b\u0445, \u0445\u043e\u0442\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u043d\u0438\u043c \u043f\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u043e.<\/p>\n<p>\u0420\u0435\u0448\u0435\u043d\u0438\u0435? <strong>\u041b\u0435\u043d\u0438\u0432\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f<\/strong> \u2014 \u043f\u043e\u0434\u0445\u043e\u0434, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u0438 \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u043d\u044b.<br \/> \u0412 PHP \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u0432\u0443\u043c\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438: \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <strong>\u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432<\/strong> <code>(yield) <\/code>\u0438 \u0447\u0435\u0440\u0435\u0437 <strong>Iterator API<\/strong>. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u043e\u0431\u0430.<\/p>\n<h4>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043b\u0435\u043d\u0438\u0432\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f<\/h4>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043c\u0430\u0441\u0441\u0438\u0432, PHP \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0432 \u043f\u0430\u043c\u044f\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b:<\/p>\n<pre><code class=\"php\">function getNumbersArray(int $count): array {     $result = [];     for ($i = 1; $i &lt;= $count; $i++) {         $result[] = $i;     }     return $result; }  foreach (getNumbersArray(5) as $number) {     echo $number . PHP_EOL; }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0441\u0440\u0430\u0437\u0443 \u0432\u0435\u0441\u044c \u043c\u0430\u0441\u0441\u0438\u0432 <code>[1, 2, 3, 4, 5]<\/code>.<\/p>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043b\u0435\u043d\u0438\u0432\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434:<\/p>\n<pre><code class=\"php\">function getNumbersGenerator(int $count): Generator {     for ($i = 1; $i &lt;= $count; $i++) {         yield $i;     } }  foreach (getNumbersGenerator(5) as $number) {     echo $number . PHP_EOL; }<\/code><\/pre>\n<p>\ud83d\udccc \u0420\u0430\u0437\u043d\u0438\u0446\u0430: \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 <strong>\u043d\u0435 \u0445\u0440\u0430\u043d\u0438\u0442 \u0432\u0441\u0451<\/strong> \u2014 \u043e\u043d \u043e\u0442\u0434\u0430\u0451\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 <code>foreach<\/code> \u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0438\u0442.<\/p>\n<h4>\u0427\u0438\u0442\u0430\u0435\u043c \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0439 CSV \u0431\u0435\u0437 \u0431\u043e\u043b\u0438<\/h4>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0444\u0430\u0439\u043b <code>data.csv<\/code> \u043d\u0430 2 \u0413\u0411. \u041e\u0431\u044b\u0447\u043d\u044b\u0439 <code>file()<\/code> \u0438\u043b\u0438 <code>fgetcsv<\/code> \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u2014 \u043c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u044b\u0439 Out of Memory.<br \/> \u0421 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c \u2014 \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e:<\/p>\n<pre><code class=\"php\">function readCsv(string $filename): Generator {     $handle = fopen($filename, 'r');     if ($handle === false) {         throw new RuntimeException(\"\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0444\u0430\u0439\u043b $filename\");     }      while (($row = fgetcsv($handle)) !== false) {         yield $row;     }      fclose($handle); }  foreach (readCsv('data.csv') as $row) {     \/\/ \u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443 }<\/code><\/pre>\n<p>\ud83d\udcca <strong>\u041f\u0430\u043c\u044f\u0442\u044c<\/strong>: \u0434\u0430\u0436\u0435 \u0434\u043b\u044f 2 \u0413\u0411 CSV \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c <strong>\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u0438\u043b\u043e\u0431\u0430\u0439\u0442<\/strong>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0430.<\/p>\n<h4>\u0411\u0435\u043d\u0447\u043c\u0430\u0440\u043a: \u043c\u0430\u0441\u0441\u0438\u0432 vs \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440<\/h4>\n<pre><code class=\"php\">$startMemory = memory_get_usage();  $array = range(1, 1_000_000); \/\/ \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u0437 \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u0430 \u0447\u0438\u0441\u0435\u043b  echo \"\u041c\u0430\u0441\u0441\u0438\u0432: \" . (memory_get_usage() - $startMemory) \/ 1024 \/ 1024 . \" MB\\n\";  unset($array);  $startMemory = memory_get_usage();  function bigGenerator(): Generator {     for ($i = 1; $i &lt;= 1_000_000; $i++) {         yield $i;     } }  foreach (bigGenerator() as $n) {     \/\/ \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c }  echo \"\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440: \" . (memory_get_usage() - $startMemory) \/ 1024 \/ 1024 . \" MB\\n\";<\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0430 \u043c\u043e\u0435\u0439 \u043c\u0430\u0448\u0438\u043d\u0435:<\/p>\n<pre><code class=\"css\">\u041c\u0430\u0441\u0441\u0438\u0432: 120 MB \u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440: 0.5 MB<\/code><\/pre>\n<h4>Iterator API<\/h4>\n<p>\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u2014 \u044d\u0442\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0438 \u043f\u0440\u043e\u0441\u0442\u043e. \u041d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e <strong>\u0431\u043e\u043b\u044c\u0448\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f<\/strong>: \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u043c\u0435\u043d\u044f\u0442\u044c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0434\u0430\u043d\u043d\u044b\u0445.<br \/>\u0422\u043e\u0433\u0434\u0430 \u0432 \u0431\u043e\u0439 \u0438\u0434\u0451\u0442 Iterator API.<\/p>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440: \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440<\/h3>\n<pre><code class=\"php\">class RangeIterator implements Iterator {     private int $start;     private int $end;     private int $current;      public function __construct(int $start, int $end) {         $this-&gt;start = $start;         $this-&gt;end = $end;         $this-&gt;current = $start;     }      public function current(): int {         return $this-&gt;current;     }      public function key(): int {         return $this-&gt;current;     }      public function next(): void {         $this-&gt;current++;     }      public function rewind(): void {         $this-&gt;current = $this-&gt;start;     }      public function valid(): bool {         return $this-&gt;current &lt;= $this-&gt;end;     } }  foreach (new RangeIterator(1, 5) as $num) {     echo $num . PHP_EOL; } <\/code><\/pre>\n<h4>\u041a\u043e\u0433\u0434\u0430 \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c<\/h4>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p>\u0421\u0438\u0442\u0443\u0430\u0446\u0438\u044f<\/p>\n<\/th>\n<th>\n<p>\u0427\u0442\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u0434\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043c\u0435\u0440\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041d\u0443\u0436\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u043b\u0438 \u0441\u043b\u043e\u0436\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>Iterator API<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041f\u043e\u0442\u043e\u043a\u043e\u0432\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430\/\u0411\u0414<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043e\u0431\u0445\u043e\u0434\u044b \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0441 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>Iterator API<\/strong><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h4>\u0420\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u0435\u0439\u0441 \u0438\u0437 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0430<\/h4>\n<p>\u041c\u044b \u043f\u0430\u0440\u0441\u0438\u043b\u0438 API \u0430\u0432\u0442\u043e\u043f\u0440\u043e\u0434\u0430\u0436, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b\u043e <strong>\u0441\u043e\u0442\u043d\u0438 \u0442\u044b\u0441\u044f\u0447 \u0437\u0430\u043f\u0438\u0441\u0435\u0439<\/strong>.<br \/> \u0420\u0430\u043d\u044c\u0448\u0435 \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u043b\u0438 \u0432\u0441\u0451 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \u2014 \u0441\u043a\u0440\u0438\u043f\u0442 \u0435\u043b \u043f\u043e 1\u20132 \u0413\u0411 \u043f\u0430\u043c\u044f\u0442\u0438.<br \/> \u041f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043d\u0430 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440:<\/p>\n<pre><code class=\"php\">function fetchCars(): Generator {     $page = 1;     do {         $data = apiRequest('cars', ['page' =&gt; $page]);         foreach ($data['items'] as $car) {             yield $car;         }         $page++;     } while (!empty($data['items'])); }<\/code><\/pre>\n<p>\ud83d\udcc9 \u041f\u0430\u043c\u044f\u0442\u044c \u0443\u043f\u0430\u043b\u0430 \u0441 <strong>2 \u0413\u0411 \u0434\u043e 10 \u041c\u0411<\/strong>, \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u0447\u0442\u0438 \u0442\u0435\u043c \u0436\u0435.<\/p>\n<h4>\ud83d\udd0d \u0414\u043b\u044f \u00ab\u0433\u0438\u043a\u043e\u0432\u00bb: \u043a\u0430\u043a \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c<\/h4>\n<h3>1. \u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u2014 \u044d\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442<\/h3>\n<p>\u0412 PHP \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u2014 \u044d\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 <code>Generator<\/code>, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 <code>Iterator<\/code> \u0438 <code>Traversable<\/code>.<br \/> \u041e\u043d \u0443\u043c\u0435\u0435\u0442:<\/p>\n<ul>\n<li>\n<p>\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438;<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043d\u0430 <code>yield<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0441 \u0442\u043e\u0433\u043e \u0436\u0435 \u043c\u0435\u0441\u0442\u0430.<\/p>\n<\/li>\n<\/ul>\n<h3>2. \u0416\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b<\/h3>\n<ol>\n<li>\n<p>\u0412\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <strong>\u043d\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0435\u0451 \u0441\u0440\u0430\u0437\u0443<\/strong> \u2014 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 <code>Generator<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0438\u0434\u0451\u0442 \u0434\u043e <code>yield<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>yield<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438 \u00ab\u0437\u0430\u043c\u043e\u0440\u0430\u0436\u0438\u0432\u0430\u0435\u0442\u00bb \u0444\u0443\u043d\u043a\u0446\u0438\u044e.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0441 \u0442\u043e\u0433\u043e \u0436\u0435 \u043c\u0435\u0441\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u2014 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u043f\u043e\u043c\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0437\u0430\u0432\u0435\u0440\u0448\u0451\u043d\u043d\u044b\u0439.<\/p>\n<\/li>\n<\/ol>\n<h3>3. \u041d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 Zend Engine<\/h3>\n<p>\u0415\u0441\u043b\u0438 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 <code>yield<\/code> \u0447\u0435\u0440\u0435\u0437 VLD (Vulcan Logic Disassembler), \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 <code>yield<\/code> \u2014 \u044d\u0442\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f:<\/p>\n<ul>\n<li>\n<p>\u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0441\u0442\u0435\u043a \u0432\u044b\u0437\u043e\u0432\u043e\u0432;<\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435;<\/p>\n<\/li>\n<li>\n<p>\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043a\u043e\u0434.<\/p>\n<\/li>\n<\/ul>\n<h3>4. \u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u043c\u0438<\/h3>\n<ul>\n<li>\n<p>\u041c\u0430\u0441\u0441\u0438\u0432 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 <strong>\u0432\u0441\u0435<\/strong> \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0445\u0440\u0430\u043d\u0438\u0442 <strong>\u043e\u0434\u0438\u043d \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442<\/strong> (<code>zval<\/code>) \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0435\u0433\u043e.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438 \u043c\u0438\u043b\u043b\u0438\u043e\u043d \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u0430\u0440\u0443 \u0441\u043e\u0442\u0435\u043d \u043a\u0438\u043b\u043e\u0431\u0430\u0439\u0442.<\/p>\n<\/li>\n<\/ul>\n<h3>5. \u041f\u0440\u0438\u043c\u0435\u0440 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0433\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430<\/h3>\n<pre><code class=\"php\">function counter(): Generator {     $i = 0;     while (true) {         yield $i++;     } }  foreach (counter() as $num) {     if ($num &gt; 5) break;     echo $num . PHP_EOL; }<\/code><\/pre>\n<p>\u0421 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c \u044d\u0442\u043e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u2014 \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u0441\u044f.<\/p>\n<h3>Benchmark results (1,000,001 rows)<\/h3>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">Method<\/p>\n<\/th>\n<th>\n<p align=\"left\">Time<\/p>\n<\/th>\n<th>\n<p align=\"left\">Memory used<\/p>\n<\/th>\n<th>\n<p align=\"left\">Peak diff<\/p>\n<\/th>\n<th>\n<p align=\"left\">Rows<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Array (eager)<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.401s<\/p>\n<\/td>\n<td>\n<p align=\"left\">120 B<\/p>\n<\/td>\n<td>\n<p align=\"left\">395.92 MB<\/p>\n<\/td>\n<td>\n<p align=\"left\">1,000,001<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Generator<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.012s<\/p>\n<\/td>\n<td>\n<p align=\"left\">0 B<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.00 MB<\/p>\n<\/td>\n<td>\n<p align=\"left\">1,000,001<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u042d\u0442\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442, \u0447\u0442\u043e \u043b\u0435\u043d\u0438\u0432\u044b\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u043c\u043e\u0433\u0443\u0442 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043d\u0430\u0431\u043e\u0440\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a CSV.<\/p>\n<h3>\u0412\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b<\/h3>\n<p>\u041f\u0438\u043a\u043e\u0432\u044b\u0439 \u0440\u0430\u0441\u0445\u043e\u0434 \u043f\u0430\u043c\u044f\u0442\u0438:<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9b0\/8f8\/9e5\/9b08f89e52a4a9a6a8e41cb98c088ef2.webp\" width=\"800\" height=\"480\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/9b0\/8f8\/9e5\/9b08f89e52a4a9a6a8e41cb98c088ef2.webp 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9b0\/8f8\/9e5\/9b08f89e52a4a9a6a8e41cb98c088ef2.webp 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u0412\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f:<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ac6\/7c3\/ee3\/ac67c3ee3b05be043a0e817653146747.webp\" width=\"800\" height=\"480\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/ac6\/7c3\/ee3\/ac67c3ee3b05be043a0e817653146747.webp 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ac6\/7c3\/ee3\/ac67c3ee3b05be043a0e817653146747.webp 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<h4>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/h4>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0451 \u0441\u0430\u043c\u0438 \u2014 \u043a\u043e\u0434, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435, \u0438\u043c\u0435\u0435\u0442 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434:<\/p>\n<p>\ud83d\udc49\u00a0<a href=\"https:\/\/github.com\/phpner\/phpner-php-lazy-evaluation-demo\" rel=\"noopener noreferrer nofollow\">github.com\/phpner\/phpner-php-lazy-evaluation-demo<\/a><\/p>\n<p>\u0412\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f:<\/p>\n<p>\u0422\u0435\u0441\u0442 CSV: \u043c\u0430\u0441\u0441\u0438\u0432 (\u0436\u0430\u0434\u043d\u044b\u0439) \u043f\u0440\u043e\u0442\u0438\u0432 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430 (\u043b\u0435\u043d\u0438\u0432\u044b\u0439)<br \/> \u041c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u0430 NDJSON<br \/> \u041f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438<br \/> \u0418\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 CLI<br \/> \u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445<br \/> \u0422\u0435\u0441\u0442\u044b PHPUnit<\/p>\n<h4>\u0412\u044b\u0432\u043e\u0434<\/h4>\n<ul>\n<li>\n<p>\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b (<code>yield<\/code>) \u0438 Iterator API \u2014 must-have \u0434\u043b\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041e\u043d\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u044b \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0431\u0435\u0437 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0438 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u2014 \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432, Iterator API \u2014 \u0434\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0435\u0449\u0451 \u0438\u043c\u0438 \u043d\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u2014 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435.<\/p>\n<\/li>\n<\/ul>\n<p>\ud83d\udcac \u0410 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0435? \u041f\u043e\u0434\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u0441\u0432\u043e\u0438\u043c\u0438 \u043a\u0435\u0439\u0441\u0430\u043c\u0438!<\/p>\n<h4>\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a<\/h4>\n<p><a href=\"https:\/\/dev.to\/oleksandr_vasyliev\/lazy-evaluation-in-php-how-generators-and-iterators-save-memory-and-speed-up-code-3529\" rel=\"noopener noreferrer nofollow\">\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u0430 \u043d\u0430 <\/a><a href=\"http:\/\/dev.to\" rel=\"noopener noreferrer nofollow\">dev.to<\/a><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/939814\/\"> https:\/\/habr.com\/ru\/articles\/939814\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u044b \u043a\u043e\u0433\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u044b\u0442\u0430\u043b\u0438\u0441\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0432 \u043f\u0430\u043c\u044f\u0442\u044c CSV-\u0444\u0430\u0439\u043b \u043d\u0430 <strong>\u043c\u0438\u043b\u043b\u0438\u043e\u043d \u0441\u0442\u0440\u043e\u043a<\/strong> \u0438 \u0443\u0432\u0438\u0434\u0435\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435:<\/p>\n<pre><code class=\"php\">PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted<\/code><\/pre>\n<p>\u0414\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c <code>memory_limit<\/code>, \u043e\u0449\u0443\u0449\u0435\u043d\u0438\u0435 \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u043e\u0435: \u043c\u044b \u0434\u0435\u0440\u0436\u0438\u043c \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432\u0435\u0441\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u0434\u0430\u043d\u043d\u044b\u0445, \u0445\u043e\u0442\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u043d\u0438\u043c \u043f\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u043e.<\/p>\n<p>\u0420\u0435\u0448\u0435\u043d\u0438\u0435? <strong>\u041b\u0435\u043d\u0438\u0432\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f<\/strong> \u2014 \u043f\u043e\u0434\u0445\u043e\u0434, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u0438 \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u043d\u044b.<br \/> \u0412 PHP \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u0432\u0443\u043c\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438: \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <strong>\u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432<\/strong> <code>(yield) <\/code>\u0438 \u0447\u0435\u0440\u0435\u0437 <strong>Iterator API<\/strong>. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u043e\u0431\u0430.<\/p>\n<h4>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043b\u0435\u043d\u0438\u0432\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f<\/h4>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043c\u0430\u0441\u0441\u0438\u0432, PHP \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0432 \u043f\u0430\u043c\u044f\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b:<\/p>\n<pre><code class=\"php\">function getNumbersArray(int $count): array {     $result = [];     for ($i = 1; $i &lt;= $count; $i++) {         $result[] = $i;     }     return $result; }  foreach (getNumbersArray(5) as $number) {     echo $number . PHP_EOL; }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0441\u0440\u0430\u0437\u0443 \u0432\u0435\u0441\u044c \u043c\u0430\u0441\u0441\u0438\u0432 <code>[1, 2, 3, 4, 5]<\/code>.<\/p>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043b\u0435\u043d\u0438\u0432\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434:<\/p>\n<pre><code class=\"php\">function getNumbersGenerator(int $count): Generator {     for ($i = 1; $i &lt;= $count; $i++) {         yield $i;     } }  foreach (getNumbersGenerator(5) as $number) {     echo $number . PHP_EOL; }<\/code><\/pre>\n<p>\ud83d\udccc \u0420\u0430\u0437\u043d\u0438\u0446\u0430: \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 <strong>\u043d\u0435 \u0445\u0440\u0430\u043d\u0438\u0442 \u0432\u0441\u0451<\/strong> \u2014 \u043e\u043d \u043e\u0442\u0434\u0430\u0451\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 <code>foreach<\/code> \u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0438\u0442.<\/p>\n<h4>\u0427\u0438\u0442\u0430\u0435\u043c \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0439 CSV \u0431\u0435\u0437 \u0431\u043e\u043b\u0438<\/h4>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0444\u0430\u0439\u043b <code>data.csv<\/code> \u043d\u0430 2 \u0413\u0411. \u041e\u0431\u044b\u0447\u043d\u044b\u0439 <code>file()<\/code> \u0438\u043b\u0438 <code>fgetcsv<\/code> \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u2014 \u043c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u044b\u0439 Out of Memory.<br \/> \u0421 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c \u2014 \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e:<\/p>\n<pre><code class=\"php\">function readCsv(string $filename): Generator {     $handle = fopen($filename, 'r');     if ($handle === false) {         throw new RuntimeException(\"\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0444\u0430\u0439\u043b $filename\");     }      while (($row = fgetcsv($handle)) !== false) {         yield $row;     }      fclose($handle); }  foreach (readCsv('data.csv') as $row) {     \/\/ \u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443 }<\/code><\/pre>\n<p>\ud83d\udcca <strong>\u041f\u0430\u043c\u044f\u0442\u044c<\/strong>: \u0434\u0430\u0436\u0435 \u0434\u043b\u044f 2 \u0413\u0411 CSV \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c <strong>\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u0438\u043b\u043e\u0431\u0430\u0439\u0442<\/strong>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0430.<\/p>\n<h4>\u0411\u0435\u043d\u0447\u043c\u0430\u0440\u043a: \u043c\u0430\u0441\u0441\u0438\u0432 vs \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440<\/h4>\n<pre><code class=\"php\">$startMemory = memory_get_usage();  $array = range(1, 1_000_000); \/\/ \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u0437 \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u0430 \u0447\u0438\u0441\u0435\u043b  echo \"\u041c\u0430\u0441\u0441\u0438\u0432: \" . (memory_get_usage() - $startMemory) \/ 1024 \/ 1024 . \" MB\\n\";  unset($array);  $startMemory = memory_get_usage();  function bigGenerator(): Generator {     for ($i = 1; $i &lt;= 1_000_000; $i++) {         yield $i;     } }  foreach (bigGenerator() as $n) {     \/\/ \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c }  echo \"\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440: \" . (memory_get_usage() - $startMemory) \/ 1024 \/ 1024 . \" MB\\n\";<\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0430 \u043c\u043e\u0435\u0439 \u043c\u0430\u0448\u0438\u043d\u0435:<\/p>\n<pre><code class=\"css\">\u041c\u0430\u0441\u0441\u0438\u0432: 120 MB \u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440: 0.5 MB<\/code><\/pre>\n<h4>Iterator API<\/h4>\n<p>\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u2014 \u044d\u0442\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0438 \u043f\u0440\u043e\u0441\u0442\u043e. \u041d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e <strong>\u0431\u043e\u043b\u044c\u0448\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f<\/strong>: \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u043c\u0435\u043d\u044f\u0442\u044c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0434\u0430\u043d\u043d\u044b\u0445.<br \/>\u0422\u043e\u0433\u0434\u0430 \u0432 \u0431\u043e\u0439 \u0438\u0434\u0451\u0442 Iterator API.<\/p>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440: \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440<\/h3>\n<pre><code class=\"php\">class RangeIterator implements Iterator {     private int $start;     private int $end;     private int $current;      public function __construct(int $start, int $end) {         $this-&gt;start = $start;         $this-&gt;end = $end;         $this-&gt;current = $start;     }      public function current(): int {         return $this-&gt;current;     }      public function key(): int {         return $this-&gt;current;     }      public function next(): void {         $this-&gt;current++;     }      public function rewind(): void {         $this-&gt;current = $this-&gt;start;     }      public function valid(): bool {         return $this-&gt;current &lt;= $this-&gt;end;     } }  foreach (new RangeIterator(1, 5) as $num) {     echo $num . PHP_EOL; } <\/code><\/pre>\n<h4>\u041a\u043e\u0433\u0434\u0430 \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c<\/h4>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p>\u0421\u0438\u0442\u0443\u0430\u0446\u0438\u044f<\/p>\n<\/th>\n<th>\n<p>\u0427\u0442\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u0434\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043c\u0435\u0440\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041d\u0443\u0436\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u043b\u0438 \u0441\u043b\u043e\u0436\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>Iterator API<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041f\u043e\u0442\u043e\u043a\u043e\u0432\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430\/\u0411\u0414<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043e\u0431\u0445\u043e\u0434\u044b \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0441 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>Iterator API<\/strong><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h4>\u0420\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u0435\u0439\u0441 \u0438\u0437 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0430<\/h4>\n<p>\u041c\u044b \u043f\u0430\u0440\u0441\u0438\u043b\u0438 API \u0430\u0432\u0442\u043e\u043f\u0440\u043e\u0434\u0430\u0436, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b\u043e <strong>\u0441\u043e\u0442\u043d\u0438 \u0442\u044b\u0441\u044f\u0447 \u0437\u0430\u043f\u0438\u0441\u0435\u0439<\/strong>.<br \/> \u0420\u0430\u043d\u044c\u0448\u0435 \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u043b\u0438 \u0432\u0441\u0451 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \u2014 \u0441\u043a\u0440\u0438\u043f\u0442 \u0435\u043b \u043f\u043e 1\u20132 \u0413\u0411 \u043f\u0430\u043c\u044f\u0442\u0438.<br \/> \u041f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043d\u0430 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440:<\/p>\n<pre><code class=\"php\">function fetchCars(): Generator {     $page = 1;     do {         $data = apiRequest('cars', ['page' =&gt; $page]);         foreach ($data['items'] as $car) {             yield $car;         }         $page++;     } while (!empty($data['items'])); }<\/code><\/pre>\n<p>\ud83d\udcc9 \u041f\u0430\u043c\u044f\u0442\u044c \u0443\u043f\u0430\u043b\u0430 \u0441 <strong>2 \u0413\u0411 \u0434\u043e 10 \u041c\u0411<\/strong>, \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u0447\u0442\u0438 \u0442\u0435\u043c \u0436\u0435.<\/p>\n<h4>\ud83d\udd0d \u0414\u043b\u044f \u00ab\u0433\u0438\u043a\u043e\u0432\u00bb: \u043a\u0430\u043a \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c<\/h4>\n<h3>1. \u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u2014 \u044d\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442<\/h3>\n<p>\u0412 PHP \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u2014 \u044d\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 <code>Generator<\/code>, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 <code>Iterator<\/code> \u0438 <code>Traversable<\/code>.<br \/> \u041e\u043d \u0443\u043c\u0435\u0435\u0442:<\/p>\n<ul>\n<li>\n<p>\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438;<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043d\u0430 <code>yield<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0441 \u0442\u043e\u0433\u043e \u0436\u0435 \u043c\u0435\u0441\u0442\u0430.<\/p>\n<\/li>\n<\/ul>\n<h3>2. \u0416\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b<\/h3>\n<ol>\n<li>\n<p>\u0412\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <strong>\u043d\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0435\u0451 \u0441\u0440\u0430\u0437\u0443<\/strong> \u2014 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 <code>Generator<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0438\u0434\u0451\u0442 \u0434\u043e <code>yield<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>yield<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438 \u00ab\u0437\u0430\u043c\u043e\u0440\u0430\u0436\u0438\u0432\u0430\u0435\u0442\u00bb \u0444\u0443\u043d\u043a\u0446\u0438\u044e.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0441 \u0442\u043e\u0433\u043e \u0436\u0435 \u043c\u0435\u0441\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u2014 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u043f\u043e\u043c\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0437\u0430\u0432\u0435\u0440\u0448\u0451\u043d\u043d\u044b\u0439.<\/p>\n<\/li>\n<\/ol>\n<h3>3. \u041d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 Zend Engine<\/h3>\n<p>\u0415\u0441\u043b\u0438 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 <code>yield<\/code> \u0447\u0435\u0440\u0435\u0437 VLD (Vulcan Logic Disassembler), \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 <code>yield<\/code> \u2014 \u044d\u0442\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f:<\/p>\n<ul>\n<li>\n<p>\u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0441\u0442\u0435\u043a \u0432\u044b\u0437\u043e\u0432\u043e\u0432;<\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435;<\/p>\n<\/li>\n<li>\n<p>\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043a\u043e\u0434.<\/p>\n<\/li>\n<\/ul>\n<h3>4. \u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u043c\u0438<\/h3>\n<ul>\n<li>\n<p>\u041c\u0430\u0441\u0441\u0438\u0432 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 <strong>\u0432\u0441\u0435<\/strong> \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0445\u0440\u0430\u043d\u0438\u0442 <strong>\u043e\u0434\u0438\u043d \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442<\/strong> (<code>zval<\/code>) \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0435\u0433\u043e.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438 \u043c\u0438\u043b\u043b\u0438\u043e\u043d \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u0430\u0440\u0443 \u0441\u043e\u0442\u0435\u043d \u043a\u0438\u043b\u043e\u0431\u0430\u0439\u0442.<\/p>\n<\/li>\n<\/ul>\n<h3>5. \u041f\u0440\u0438\u043c\u0435\u0440 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0433\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430<\/h3>\n<pre><code class=\"php\">function counter(): Generator {     $i = 0;     while (true) {         yield $i++;     } }  foreach (counter() as $num) {     if ($num &gt; 5) break;     echo $num . PHP_EOL; }<\/code><\/pre>\n<p>\u0421 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c \u044d\u0442\u043e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u2014 \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u0441\u044f.<\/p>\n<h3>Benchmark results (1,000,001 rows)<\/h3>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">Method<\/p>\n<\/th>\n<th>\n<p align=\"left\">Time<\/p>\n<\/th>\n<th>\n<p align=\"left\">Memory used<\/p>\n<\/th>\n<th>\n<p align=\"left\">Peak diff<\/p>\n<\/th>\n<th>\n<p align=\"left\">Rows<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Array (eager)<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.401s<\/p>\n<\/td>\n<td>\n<p align=\"left\">120 B<\/p>\n<\/td>\n<td>\n<p align=\"left\">395.92 MB<\/p>\n<\/td>\n<td>\n<p align=\"left\">1,000,001<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Generator<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.012s<\/p>\n<\/td>\n<td>\n<p align=\"left\">0 B<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.00 MB<\/p>\n<\/td>\n<td>\n<p align=\"left\">1,000,001<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u042d\u0442\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442, \u0447\u0442\u043e \u043b\u0435\u043d\u0438\u0432\u044b\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u043c\u043e\u0433\u0443\u0442 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043d\u0430\u0431\u043e\u0440\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a CSV.<\/p>\n<h3>\u0412\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b<\/h3>\n<p>\u041f\u0438\u043a\u043e\u0432\u044b\u0439 \u0440\u0430\u0441\u0445\u043e\u0434 \u043f\u0430\u043c\u044f\u0442\u0438:<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0412\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f:<\/p>\n<figure class=\"full-width\"><\/figure>\n<h4>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/h4>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0451 \u0441\u0430\u043c\u0438 \u2014 \u043a\u043e\u0434, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435, \u0438\u043c\u0435\u0435\u0442 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434:<\/p>\n<p>\ud83d\udc49\u00a0<a href=\"https:\/\/github.com\/phpner\/phpner-php-lazy-evaluation-demo\" rel=\"noopener noreferrer nofollow\">github.com\/phpner\/phpner-php-lazy-evaluation-demo<\/a><\/p>\n<p>\u0412\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f:<\/p>\n<p>\u0422\u0435\u0441\u0442 CSV: \u043c\u0430\u0441\u0441\u0438\u0432 (\u0436\u0430\u0434\u043d\u044b\u0439) \u043f\u0440\u043e\u0442\u0438\u0432 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430 (\u043b\u0435\u043d\u0438\u0432\u044b\u0439)<br \/> \u041c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u0430 NDJSON<br \/> \u041f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438<br \/> \u0418\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 CLI<br \/> \u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445<br \/> \u0422\u0435\u0441\u0442\u044b PHPUnit<\/p>\n<h4>\u0412\u044b\u0432\u043e\u0434<\/h4>\n<ul>\n<li>\n<p>\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b (<code>yield<\/code>) \u0438 Iterator API \u2014 must-have \u0434\u043b\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041e\u043d\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u044b \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0431\u0435\u0437 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0438 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u2014 \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432, Iterator API \u2014 \u0434\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0435\u0449\u0451 \u0438\u043c\u0438 \u043d\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u2014 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435.<\/p>\n<\/li>\n<\/ul>\n<p>\ud83d\udcac \u0410 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0435? \u041f\u043e\u0434\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u0441\u0432\u043e\u0438\u043c\u0438 \u043a\u0435\u0439\u0441\u0430\u043c\u0438!<\/p>\n<h4>\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a<\/h4>\n<p><a href=\"https:\/\/dev.to\/oleksandr_vasyliev\/lazy-evaluation-in-php-how-generators-and-iterators-save-memory-and-speed-up-code-3529\" rel=\"noopener noreferrer nofollow\">\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u0430 \u043d\u0430 <\/a><a href=\"http:\/\/dev.to\" rel=\"noopener noreferrer nofollow\">dev.to<\/a><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/939814\/\"> https:\/\/habr.com\/ru\/articles\/939814\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-471637","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/471637","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=471637"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/471637\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=471637"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=471637"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=471637"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}