Bug #78965 [Com]: print causes segmentation error when client lost connection to server.
Edit report at https://bugs.php.net/bug.php?id=78965&edit=1
ID: 78965
Comment by: thedinosaurmail at gmail dot com
Reported by: intlwangzp at gmail dot com
Summary: print causes segmentation error when client lost
connection to server.
Status: Open
Type: Bug
Package: *General Issues
Operating System: Debian GNU/Linux 10 (buster)
PHP Version: 7.3.12
Block user comment: N
Private report: N
New Comment:
in my computer is work ok
Previous Comments:
------------------------------------------------------------------------
[2019-12-15 23:36:54] intlwangzp at gmail dot com
Description:
------------
php corrupts with the following error log:
[Sun Dec 15 23:37:29.394166 2019] [core:notice] [pid 5439] AH00094: Command line:
'/usr/sbin/apache2'
[Sun Dec 15 23:45:59.115631 2019] [core:notice] [pid 5439] AH00052: child pid 5444 exit signal
Segmentation fault (11)
[Sun Dec 15 23:45:59.115799 2019] [core:notice] [pid 5439] AH00052: child pid 5457 exit signal
Segmentation fault (11)
[Sun Dec 15 23:45:59.115901 2019] [mpm_prefork:notice] [pid 5439] AH00169: caught SIGTERM, shutting
down
[Sun Dec 15 23:45:59.280035 2019] [mpm_prefork:notice] [pid 5615] AH00163: Apache/2.4.38 (Debian)
configured -- resuming normal operations
[Sun Dec 15 23:45:59.280156 2019] [core:notice] [pid 5615] AH00094: Command line:
'/usr/sbin/apache2'
This error happens when I test the video stream function and print the buffer read from a local
media file. If client closes the internet connection for example by disconnecting wifi while the
video is still playing and data is still downloading, print function will cause a segmentation
fault.
The code comes originally from http://infinityquest.com/php-tutorials/program-http-range-in-php/
and the critical line number is #148. If we use echo instead of print, problem is then solved.
Test script:
---------------
// Move the proper place in the file
// And print out the requested piece in chunks
function send_range($handle, $start, $end) {
$line_length = 4096; // magic number
if (fseek($handle, $start) === -1) {
error_log("Error: fseek() fail.");
}
$left_to_read = $end - $start + 1;
do {
$length = min($line_length, $left_to_read);
if (($buffer = fread($handle, $length)) !== false) {
// print $buffer; // ***** BUG if use print *****
echo $buffer; // ***** ok *****
} else {
error_log("Error: fread() fail.");
}
} while ($left_to_read -= $length);
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78965&edit=1
Thread (2 messages)