Answer the question
In order to leave comments, you need to log in
Why doesn't php-fpm stop when connection is cancelled?
Check with the following script
<?php
ignore_user_abort(false);
echo 'message';
sleep(8);
while(ob_get_level()) {
ob_end_flush();
}
$status = connection_status();
if ($aborted = connection_aborted()) {
file_put_contents(__DIR__ . '/a', date('d.m.Y H:i:s') . ' - aborted (' . $aborted . '); Status - ' . $status);
echo 'aborted';
} else {
file_put_contents(__DIR__ . '/a', date('d.m.Y H:i:s') . ' - connected (' . $aborted . '); Status - ' . $status);
echo 'connected';
}
Answer the question
In order to leave comments, you need to log in
It only worked with a socket connection.
PHP also learns about a connection failure only after sending data to the client (via echo, header) and flushing the buffer.
The code will be as follows
<?php
//Работает только при socket соединении
//необходимо выставить в true. Иначе после вывода данных выполнение скрипта прервется
ignore_user_abort(true);
sleep(8);
echo 'message';
flush();//только теперь php знает, оборвалось соединение или нет
$status = connection_status();
if ($aborted = connection_aborted()) {
file_put_contents(__DIR__ . '/a', date('d.m.Y H:i:s') . ' - aborted (' . $aborted . '); Status - ' . $status);
echo 'aborted';
} else {
file_put_contents(__DIR__ . '/a', date('d.m.Y H:i:s') . ' - connected (' . $aborted . '); Status - ' . $status);
echo 'connected';
}
All lengthy operations must be performed outside the web interface.
From the web interface, you only need to add tasks for such commands/servers.
your way to nowhere give up this shit code and do everything right, not a crutch on a crutch.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question