|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-03-15 19:08 UTC] michael dot mauch at gmx dot de
Description:
------------
I'm using a function like below to redirect all output to a log file in PHP CLI scripts.
It works until PHP 7.1, but crashes with SIGSEGV in 7.2 and 7.3. If I use old fopen() instead of SplFileObject, it also works with 7.2 and 7.3.
Oracle Linux 7.x at work, Ubuntu 16.04 at home, or even in docker with the official images.
Test script:
---------------
<?php
$logfilename = "/tmp/crash.log";
$logfile = new SplFileObject($logfilename, "w");
ob_start(function ($buffer) use ($logfile) {
$logfile->fwrite($buffer);
$logfile->fflush();
return "";
});
echo "hmm\n";
Expected result:
----------------
# Like with PHP 7.1:
% docker run -it --rm -v "$PWD":/tmp -w /tmp php:7.1-cli /bin/bash -c 'ulimit -c unlimited; php -v; php ./crash.php && echo ok'
PHP 7.1.27 (cli) (built: Mar 9 2019 02:51:22) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
ok
Actual result:
--------------
# But with PHP 7.3:
% docker run -it --rm -v "$PWD":/tmp -w /tmp php:cli /bin/bash -c 'ulimit -c unlimited; php -v; php ./crash.php && echo ok'
PHP 7.3.3 (cli) (built: Mar 9 2019 00:27:53) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.3, Copyright (c) 1998-2018 Zend Technologies
/bin/bash: line 1: 7 Segmentation fault (core dumped) php ./crash.php
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 16:00:01 2025 UTC |
Hah, I found it with git bisect: ./bisect.sh: Zeile 11: 23355 Speicherzugriffsfehler (Speicherabzug geschrieben) sapi/cli/php ~/php/crash.php 09d3b7386c7c7de1ef89ba04d00e93b2287adb00 is the first bad commit commit 09d3b7386c7c7de1ef89ba04d00e93b2287adb00 Author: Dmitry Stogov <dmitry@zend.com> Date: Wed Jul 12 18:53:16 2017 +0300 Resources should be closed during object destructioin, not during freeing. :040000 040000 5cf00a5f2339e62d800c87ee46d9827a00ad27f8 ffceeb3d9160671f1f22b7ca4d0b682e9bfc0dd4 M ext 'bisect run' erfolgreich ausgeführt What I did: git clone https://github.com/php/php-src.git cd php-src git checkout PHP-7.2 git bisect start git bisect bad HEAD # git log --oneline # searched for the first mention of PHP-7.2 from the bottom # and used the commit before that one in the hope that it was still good git checkout 6c32d27 ./buildconf ./configure --disable-all make -j10 sapi/cli/php ~/php/crash.php # worked, therefor: git bisect good # made a script to build and run ./bisect.sh # crashed, therefor: git bisect bad # let it search on its own: git bisect run ./bisect.sh After a while, it found the "bad" commit. For completeness, here's the bisect.sh that I used: #! /bin/bash make distclean ./buildconf ./configure --disable-all make -j10 if sapi/cli/php ~/php/crash.php ; then exit 0 else exit 1 fi