Fix #20718: When set_time_limit() is not available, throw a warning only for big files

This commit is contained in:
Marc Farré
2026-01-27 06:58:45 +00:00
committed by GitHub
parent 9a9a8b1e21
commit 20d576e555
2 changed files with 11 additions and 3 deletions

View File

@@ -7,6 +7,7 @@ Yii Framework 2 Change Log
- Bug #20705: Replace `$this` with `self` in generics in Psalm annotations (mspirkov)
- Bug #20715: Adjust `JSON` helper error message assertions for `PHP 8.6` compatibility in `JsonTest` class (terabytesoftw)
- Enh #20717: Use PHPStan/Psalm types in PHPDoc annotations (mspirkov)
- Enh #20718: When set_time_limit() is not available, throw a warning only for big files (@marc-farre)
2.0.54 January 09, 2026

View File

@@ -445,9 +445,7 @@ class Response extends \yii\base\Response
}
// Try to reset time limit for big files
if (!function_exists('set_time_limit') || !@set_time_limit(0)) {
Yii::warning('set_time_limit() is not available', __METHOD__);
}
$setTimeLimitFailed = !function_exists('set_time_limit') || !@set_time_limit(0);
if (is_callable($this->stream)) {
$data = call_user_func($this->stream);
@@ -460,6 +458,7 @@ class Response extends \yii\base\Response
$chunkSize = 8 * 1024 * 1024; // 8MB per chunk
$iterationCount = 0;
if (is_array($this->stream)) {
list($handle, $begin, $end) = $this->stream;
@@ -469,6 +468,10 @@ class Response extends \yii\base\Response
}
while (!feof($handle) && ($pos = ftell($handle)) <= $end) {
$iterationCount++;
if ($setTimeLimitFailed && $iterationCount === 2) {
Yii::warning('set_time_limit() is not available', __METHOD__);
}
if ($pos + $chunkSize > $end) {
$chunkSize = $end - $pos + 1;
}
@@ -478,6 +481,10 @@ class Response extends \yii\base\Response
fclose($handle);
} else {
while (!feof($this->stream)) {
$iterationCount++;
if ($setTimeLimitFailed && $iterationCount === 2) {
Yii::warning('set_time_limit() is not available', __METHOD__);
}
echo fread($this->stream, $chunkSize);
flush();
}