From 668abfee8077706134dbedbf9efcdd7b3285e273 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Fri, 2 Dec 2016 14:57:57 +0100 Subject: [PATCH] Prevent duplicate closeCallback calls in case of GC ghosts Sometimes PHP 7 GC decides to call stream_close again even after the PHP request has ended, and even if fclose was called before already. --- src/CallbackWrapper.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CallbackWrapper.php b/src/CallbackWrapper.php index c5847b9..4eef556 100644 --- a/src/CallbackWrapper.php +++ b/src/CallbackWrapper.php @@ -107,6 +107,8 @@ public function stream_close() { $result = parent::stream_close(); if (is_callable($this->closeCallback)) { call_user_func($this->closeCallback); + // prevent further calls by potential PHP 7 GC ghosts + $this->closeCallback = null; } return $result; }