php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #42585 die() in event handler => PHP hangs
Submitted: 2007-09-07 09:49 UTC Modified: 2020-11-04 13:39 UTC
Votes:8
Avg. Score:2.6 ± 0.7
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: csaba at alum dot mit dot edu Assigned: cmb (profile)
Status: Closed Package: COM related
PHP Version: 5.2.4 OS: Win XP Pro
Private report: No CVE-ID: None
 [2007-09-07 09:49 UTC] csaba at alum dot mit dot edu
Description:
------------
If I have a COM object call into PHP (via com_event_sink or IE's window.setTimeout) with a die() within the called code, then PHP hangs.

In the example below, IE comes up and waits around for 4 seconds, after which an $ie->quit() is issued.  In the event handler (function OnQuit()) a die() is issued.  While IE does shut down, PHP does not return me the command prompt.  This is from PHP CLI, of course.

Csaba Gabor from Vienna

Reproduce code:
---------------
<?php 
class IESink { 
  public $terminated = false; 
  public function TitleChange($text) { 
    echo("title has changed: $text \n"); }

  public function OnQuit() { 
    print "Quitting\n";
    die();
    print "Died\n";
    $this->terminated = true; 
  } } 

$ie = new COM("InternetExplorer.Application"); 
$ie->Visible = true; 
$sink = new IESink; 
com_event_sink($ie, $sink, "DWebBrowserEvents2"); 
$ie->Navigate("http://www.php.net/"); 

$start = time();
$quitted = false;

while (!$sink->terminated) { 
  com_message_pump(200); 
  if (time()-$start>4 && !$quitted) {
    $quitted=true;
    $ie->quit(); } } 
print "Finished!\n"; 
?>

Expected result:
----------------
I expect to be shown the following three lines, ie to go away, AND for PHP to terminate:
title has changed: PHP: Hypertext Preprocessor
title has changed: PHP: Hypertext Preprocessor
Quitting

Actual result:
--------------
The above 3 lines are shown, IE goes away, BUT php does not terminate.

Also, note that if I manually shut IE down, instead of waiting the 4 seconds, then I get the following additional line (and PHP still hangs the cmd prompt):
Fatal error: Call to undefined method com::quit() in Unknown on line 0

It seems to me that the while loop stays active, since that's the only place that $ie->quit() is issued.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-07 11:04 UTC] jani@php.net
Assigned to the COM maintainer.
 [2017-10-24 03:32 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: wharmby +Assigned To:
 [2020-11-04 13:39 UTC] cmb@php.net
-Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem -Assigned To: +Assigned To: cmb
 [2020-11-04 13:39 UTC] cmb@php.net
The problem here is that, prior to PHP 8.0.0, die() causes a so
called "unclean shutdown", what prevents the unbinding of the
bound event sink, causing a hang (or potentially other issue).
Throwing an exception instead of calling die() would solve that.
Given that this issue is fixed in PHP 8.0.0, I'm changing this to
doc problem.
 [2020-11-04 13:50 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=e604424d6d60d5cd9489bec6312c20195abe2c07
Log: Fix #42585: die() in event handler =&gt; PHP hangs
 [2020-11-04 13:50 UTC] phpdocbot@php.net
-Status: Verified +Status: Closed
 [2020-11-04 18:05 UTC] phpdocbot@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=0b849b3911c8600f4df2b5edb44c62da7229ec20
Log: Fix #42585: die() in event handler =&gt; PHP hangs
 [2020-12-30 11:58 UTC] nikic@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=6a381e8516b4f83db0dd4a63132d9ffd5881c84f
Log: Fix #42585: die() in event handler =&gt; PHP hangs
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 00:01:28 2024 UTC