Bug #67644 [Asn]: Memory corruption & crash during ob_start function callback
| From: | stas@php.net | Date: | Sun, 31 Aug 2014 00:45:05 +0000 |
| Subject: | Bug #67644 [Asn]: Memory corruption & crash during ob_start function callback | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-187355@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67644&edit=1
ID: 67644
Updated by: stas@php.net
Reported by: jocelyn dot fournier at gmail dot com
Summary: Memory corruption & crash during ob_start function
callback
Status: Assigned
Type: Bug
Package: Reproducible crash
Operating System: Mac OS X
PHP Version: 5.4.30
Assigned To: mike
Block user comment: N
Private report: N
New Comment:
Looking at the library, I see that it runs a lot of code from __destruct function which is called on
shutdown. This is usually not the best idea as the services the object needs to run his code may be
already partially shut down. I'll still see if it can be handled better, but I'm not sure
if this code will actually work properly in this way.
Previous Comments:
------------------------------------------------------------------------
[2014-08-29 14:42:59] jocelyn dot fournier at gmail dot com
I've just modified the code on https://github.com/jocel1/php5.4-crash to not
require a working AMQP server.
------------------------------------------------------------------------
[2014-08-29 07:50:12] stas@php.net
It would help a lot if there was a reproducing case that does not require running rabbitmq server.
You say you have different cases reproducing it, can any of them be cut down so that actual amqp
server is not needed to reproduce?
------------------------------------------------------------------------
[2014-08-24 17:14:11] jocelyn dot fournier at gmail dot com
Hi,
Any progress on this issue ?
Using register_shutdown_function() + ob_start() as a workaround doesn't work for all the cases.
Indeed, I are have cases where ob_start() is called before register_shutdown_function(), even with
the PHP_OUTPUT_HANDLER_REMOVABLE flag in ob_start().
Thanks,
------------------------------------------------------------------------
[2014-07-19 06:11:46] jocelyn dot fournier at gmail dot com
If I slightly modify the script to run the asynchronous_write function inside a
register_shutdown_function instead of ob_start, it doesn't crash anymore :
<?php
use PhpAmqpLib\Connection\AMQPConnection;
class queue {
private static $instance = null;
private $connection = null;
private $channel = null;
public static function instance() {
if (self::$instance == null) {
self::$instance = new self();
}
return self::$instance;
}
private function __construct() {
require_once __DIR__.'/libs/php-amqplib-2.4.0/vendor/autoload.php';
$this->connection = new AMQPConnection('localhost', '5672',
'guest', 'guest', '/');
}
public function asynchronous_write() {
if (!$this->connection) return;
if ($this->channel == null) {
$this->channel = $this->connection->channel();
}
}
}
register_shutdown_function('async');
ob_start('foo');
echo 'bar';
function async() {
queue::instance()->asynchronous_write();
}
function foo($content, $mode = 5) {
return $content;
}
exit;
------------------------------------------------------------------------
[2014-07-19 06:00:19] jocelyn dot fournier at gmail dot com
5.5.13 crashes as well
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=67644
--
Edit this bug report at https://bugs.php.net/bug.php?id=67644&edit=1