note 126345 added to function.fastcgi-finish-request
| From: | rundizdotcom at main dot php dot net | Date: | Mon, 16 Aug 2021 10:38:32 +0000 |
| Subject: | note 126345 added to function.fastcgi-finish-request | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-216798@lists.php.net to get a copy of this message | ||
Here are few example of how to using it.
The first is basic example.
<?php
$file = __DIR__ . '/text.txt';
if (is_file($file) && is_writable($file)) {
@unlink($file);
echo '<small style="color: #ccc;">' . $file . ' was
deleted.</small><br>' . PHP_EOL;
}
echo '<p>Calling to <code>fastcgi_finish_request()</code>.</p>' .
PHP_EOL;
echo '<p>If success, the file ' . $file . ' will be created.</p>' .
PHP_EOL;
if (function_exists('fastcgi_finish_request')) {
fastcgi_finish_request();
} else {
echo '<p style="color: red;">This server does not support
<code>fastcgi_finish_request()</code> function.</p>' . PHP_EOL;
echo 'Exit now.<br>' . PHP_EOL;
exit();
}
echo 'This line will be not echo out.<br>' . PHP_EOL;
file_put_contents($file, date('Y-m-d H:i:s') . PHP_EOL, FILE_APPEND);
?>
The file text.txt will be create if successfully.
==========================
The second is about execution timeout.
<?php
set_time_limit(5);
$file = __DIR__ . '/text.txt';
if (is_file($file) && is_writable($file)) {
@unlink($file);
echo '<small style="color: #ccc;">' . $file . ' was
deleted.</small><br>' . PHP_EOL;
}
echo '<p>Testing timeout and <code>fastcgi_finish_request()</code>
function.</p>' . PHP_EOL;
echo '<p>Set timeout to ' . ini_get('max_execution_time') . '
seconds.</p>' . PHP_EOL;
echo '<p>Calling to <code>fastcgi_finish_request()</code>.</p>' .
PHP_EOL;
echo '<p>If success, the file ' . $file . ' will be created but error will be
shown in the log.</p>' . PHP_EOL;
if (function_exists('fastcgi_finish_request')) {
fastcgi_finish_request();
} else {
echo '<p style="color: red;">This server does not support
<code>fastcgi_finish_request()</code> function.</p>' . PHP_EOL;
echo 'Exit now.<br>' . PHP_EOL;
exit();
}
$i = 1;
while(true){
if ($i <= 10) {
file_put_contents($file, date('Y-m-d H:i:s') . PHP_EOL, FILE_APPEND);
$i++;
}
//to infinity and beyond...
}
?>
I found that the code will be working as long as it is not reach timeout setting in php.ini or
set_time_limit() function.
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.242 (proxied: 49.228.231.99)
----
Manual Page -- https://php.net/manual/en/function.fastcgi-finish-request.php
Edit -- https://main.php.net/note/edit/126345
Del: integrated -- https://main.php.net/note/delete/126345/integrated
Del: useless -- https://main.php.net/note/delete/126345/useless
Del: bad code -- https://main.php.net/note/delete/126345/bad+code
Del: spam -- https://main.php.net/note/delete/126345/spam
Del: non-english -- https://main.php.net/note/delete/126345/non-english
Del: in docs -- https://main.php.net/note/delete/126345/in+docs
Del: other reasons-- https://main.php.net/note/delete/126345
Reject -- https://main.php.net/note/reject/126345
Search -- https://main.php.net/manage/user-notes.php