|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30743 proc_open() / proc_close() leak handles on Windows XP
Submitted: 2004-11-10 09:43 UTC Modified: 2004-11-11 07:28 UTC
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: ilya77 at gmail dot com Assigned:
Status: Closed Package: Program Execution
PHP Version: 5.0.2 OS: Windows XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: ilya77 at gmail dot com
New email:
PHP Version: OS:


 [2004-11-10 09:43 UTC] ilya77 at gmail dot com
I have a scheduler script, which constantly runs in the background, invokes processes, and pipes their output back to stdout.

It seems that proc_open() or proc_close() call leaks handles on Windows platform (I'm running PHP 5.0.2).

In the example code, the handles count would increment by 1 each time invoke() is called, in other places I saw similar code leak 4 handles at once during each iteration.

Reproduce code:

function invoke()
	$commandLine = "echo hello";

	$fileDescriptors = array(
					1 => array("pipe", "w"),
					2 => array("pipe", "w")

	$pipes = array();

	$processHandle	= proc_open($commandLine,
                                  $fileDescriptors, $pipes);

	if (is_resource($processHandle))
		foreach($pipes as $pipeID => $pipeHandle)


Expected result:
I expected the handle count to increment by X, and decrement by X after the process completes.
(where it's logical to assume that X = number of pipes + 1 for the child process handle)

Actual result:
In fact, the handles count (in windows task manager) for the php.exe process running the script incremented by 1 each time invoke() in the example code was executed.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-10 16:17 UTC] ilya77 at gmail dot com

PHP_FUNCTION(proc_close) missed a call to CloseHandle(proc->child), to close the process handle.
This is what caused the handle leak.

Here's the code:

------------- cut here -------------
/* {{{ proto int proc_close(resource process)
   close a process opened by proc_open */
	zval *zproc;
	struct php_process_handle *proc;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zproc) == FAILURE) {

	ZEND_FETCH_RESOURCE(proc, struct php_process_handle *, &zproc, -1, "process", le_proc_open);

	CloseHandle(proc->child);	// ilya.1.0 20041110

/* }}} */
------------- cut here -------------
 [2004-11-11 07:28 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

Fixed in CVS by Wez.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 13 18:01:29 2024 UTC