From dba22c08640b02e68bfea68440246fec1fb7459d Mon Sep 17 00:00:00 2001 From: Jille Timmermans Date: Tue, 15 Jan 2013 11:25:55 +0100 Subject: [PATCH] Dereferencing process-handles no longer waits on those processes. Implements FR #46487 --- NEWS | 3 +++ ext/standard/file.c | 3 +++ ext/standard/file.h | 3 ++- ext/standard/proc_open.c | 20 ++++++++++++++++---- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 4145dc54ee..212029cbee 100644 --- a/NEWS +++ b/NEWS @@ -247,4 +247,7 @@ PHP NEWS . Fixed bug #63248 (Load multiple magic files from a directory under Windows). (Anatoliy) +- General improvements: + . Implemented FR #46487 (Dereferencing process-handles no longer waits on those processes). (Jille Timmermans) + <<< NOTE: Insert NEWS from last stable release here prior to actual release! >>> diff --git a/ext/standard/file.c b/ext/standard/file.c index 74577ac495..cf8b159556 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -159,6 +159,7 @@ static ZEND_RSRC_DTOR_FUNC(file_context_dtor) static void file_globals_ctor(php_file_globals *file_globals_p TSRMLS_DC) { FG(pclose_ret) = 0; + FG(pclose_wait) = 0; FG(user_stream_current_filename) = NULL; FG(def_chunk_size) = PHP_SOCK_CHUNK_SIZE; FG(wrapper_errors) = NULL; @@ -960,7 +961,9 @@ PHP_FUNCTION(pclose) PHP_STREAM_TO_ZVAL(stream, &arg1); + FG(pclose_wait) = 1; zend_list_delete(stream->rsrc_id); + FG(pclose_wait) = 0; RETURN_LONG(FG(pclose_ret)); } /* }}} */ diff --git a/ext/standard/file.h b/ext/standard/file.h index 0a4512ecd4..2bcdfd64bf 100644 --- a/ext/standard/file.h +++ b/ext/standard/file.h @@ -115,7 +115,7 @@ typedef struct _php_meta_tags_data { php_meta_tags_token php_next_meta_token(php_meta_tags_data * TSRMLS_DC); typedef struct { - int pclose_ret; + int pclose_ret; size_t def_chunk_size; long auto_detect_line_endings; long default_socket_timeout; @@ -126,6 +126,7 @@ typedef struct { HashTable *stream_wrappers; /* per-request copy of url_stream_wrappers_hash */ HashTable *stream_filters; /* per-request copy of stream_filters_hash */ HashTable *wrapper_errors; /* key: wrapper address; value: linked list of char* */ + int pclose_wait; } php_file_globals; #ifdef ZTS diff --git a/ext/standard/proc_open.c b/ext/standard/proc_open.c index 1edfe78849..4e39a40be4 100644 --- a/ext/standard/proc_open.c +++ b/ext/standard/proc_open.c @@ -208,6 +208,7 @@ static void proc_open_rsrc_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) DWORD wstatus; #elif HAVE_SYS_WAIT_H int wstatus; + int waitpid_options = 0; pid_t wait_pid; #endif @@ -220,18 +221,27 @@ static void proc_open_rsrc_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) } #ifdef PHP_WIN32 - WaitForSingleObject(proc->childHandle, INFINITE); + if (FG(pclose_wait)) { + WaitForSingleObject(proc->childHandle, INFINITE); + } GetExitCodeProcess(proc->childHandle, &wstatus); - FG(pclose_ret) = wstatus; + if (wstatus == STILL_ACTIVE) { + FG(pclose_ret) = -1; + } else { + FG(pclose_ret) = wstatus; + } CloseHandle(proc->childHandle); #elif HAVE_SYS_WAIT_H + if (!FG(pclose_wait)) { + waitpid_options = WNOHANG; + } do { - wait_pid = waitpid(proc->child, &wstatus, 0); + wait_pid = waitpid(proc->child, &wstatus, waitpid_options); } while (wait_pid == -1 && errno == EINTR); - if (wait_pid == -1) { + if (wait_pid <= 0) { FG(pclose_ret) = -1; } else { if (WIFEXITED(wstatus)) @@ -300,7 +310,9 @@ PHP_FUNCTION(proc_close) ZEND_FETCH_RESOURCE(proc, struct php_process_handle *, &zproc, -1, "process", le_proc_open); + FG(pclose_wait) = 1; zend_list_delete(Z_LVAL_P(zproc)); + FG(pclose_wait) = 0; RETURN_LONG(FG(pclose_ret)); } /* }}} */ -- 2.40.0