php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38796 Self-call __destructor from child process
Submitted: 2006-09-12 18:28 UTC Modified: 2006-09-12 20:01 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: fiw at mail dot ru Assigned:
Status: Not a bug Package: PCNTL related
PHP Version: 5.1.6 OS: FreeBSD 6.1
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: fiw at mail dot ru
New email:
PHP Version: OS:

 

 [2006-09-12 18:28 UTC] fiw at mail dot ru
Description:
------------
No descriptions, sorry.

Reproduce code:
---------------
<?php
declare(ticks = 1);
class Daemon {
	private $threads = array();
	function __construct() {
		echo posix_getpid() . ' Daemon::construct()' . "\n";
		for ($i = 0; $i < 5; $i++) $threads[] = new Thread;
	}
	function __destruct() {
		echo posix_getpid() . ' Daemon::destruct()' . "\n";
	}
}
class Thread {
	function __construct() {
		echo posix_getpid() . ' Thread::construct()' . "\n";
		$this->pid = pcntl_fork();
		if ($this->pid == -1) throw new Exception;
		if ($this->pid) {
			pcntl_wait($status);
			return;
		}
		echo posix_getpid() . ' Thread::child()' . "\n";
		exit;
	}
	function __destruct() {
		echo posix_getpid() . ' Thread::destruct()' . "\n";
	}
}
new Daemon;
?>


Expected result:
----------------
77080 Daemon::construct()
77080 Thread::construct()
77081 Thread::child()
77081 Daemon::destruct()
77081 Thread::destruct()
77080 Thread::construct()
77082 Thread::child()
77082 Daemon::destruct()
77082 Thread::destruct()
77082 Thread::destruct()
77080 Thread::construct()
77083 Thread::child()
77083 Daemon::destruct()
77083 Thread::destruct()
77083 Thread::destruct()
77083 Thread::destruct()
77080 Thread::construct()
77084 Thread::child()
77084 Daemon::destruct()
77084 Thread::destruct()
77084 Thread::destruct()
77084 Thread::destruct()
77084 Thread::destruct()
77080 Thread::construct()
77085 Thread::child()
77085 Daemon::destruct()
77085 Thread::destruct()
77085 Thread::destruct()
77085 Thread::destruct()
77085 Thread::destruct()
77085 Thread::destruct()
77080 Thread::destruct()
77080 Thread::destruct()
77080 Thread::destruct()
77080 Thread::destruct()
77080 Thread::destruct()
77080 Daemon::destruct()


Actual result:
--------------
77080 Daemon::construct()
77080 Thread::construct()
77081 Thread::child()
77080 Thread::construct()
77082 Thread::child()
77080 Thread::construct()
77083 Thread::child()
77080 Thread::construct()
77084 Thread::child()
77080 Thread::construct()
77085 Thread::child()
77080 Thread::destruct()
77080 Thread::destruct()
77080 Thread::destruct()
77080 Thread::destruct()
77080 Thread::destruct()
77080 Daemon::destruct()


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-12 18:39 UTC] tony2001@php.net
.

 [2006-09-12 18:49 UTC] fiw at mail dot ru
Tony, it's real not bogus! Check it!
 [2006-09-12 19:03 UTC] fiw at mail dot ru
I check this code on Cygwin with PHP 5.1.4 and have similar result.
 [2006-09-12 19:08 UTC] tony2001@php.net
What do you want me to check?
Care to describe what's your problem with some more words.
 [2006-09-12 19:16 UTC] fiw at mail dot ru
Sorry, I don't know english much well. But you can see this bug in expected result - child process call not own destructors.
 [2006-09-12 19:18 UTC] tony2001@php.net
Feel free to use private mail and Russian.
 [2006-09-12 19:31 UTC] fiw at mail dot ru
Ok, thanks. You can check your mailbox.
 [2006-09-12 19:38 UTC] tony2001@php.net
fork() duplicates the parent environment, including all the variables and objects. Apparently child processes call destructors, as usual PHP processes.
No bug here.
 [2006-09-12 19:55 UTC] fiw at mail dot ru
But why child process calls only every destructors and not calls they constructors (from any objects)?
 [2006-09-12 20:01 UTC] tony2001@php.net
Child process is just a copy of parent process.
That's how fork() call works.
Constructors are not called, because they were called in the child process, _before_ the fork() call.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 09:01:28 2024 UTC