Skip to content

Commit c3c2405

Browse files
committed
Add proc_terminate() function to forcibly kill off a process created
with proc_open().
1 parent 8a07cc4 commit c3c2405

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

ext/standard/basic_functions.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ function_entry basic_functions[] = {
419419
#ifdef PHP_CAN_SUPPORT_PROC_OPEN
420420
PHP_FE(proc_open, third_arg_force_ref)
421421
PHP_FE(proc_close, NULL)
422+
PHP_FE(proc_terminate, NULL)
422423
PHP_FE(proc_get_status, NULL)
423424
#endif
424425

ext/standard/exec.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ PHP_FUNCTION(shell_exec);
3030
PHP_FUNCTION(proc_open);
3131
PHP_FUNCTION(proc_get_status);
3232
PHP_FUNCTION(proc_close);
33+
PHP_FUNCTION(proc_terminate);
3334
PHP_MINIT_FUNCTION(proc_open);
3435

3536
char *php_escape_shell_cmd(char *);

ext/standard/proc_open.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,32 @@ PHP_MINIT_FUNCTION(proc_open)
174174
return SUCCESS;
175175
}
176176

177+
178+
/* {{{ proto int proc_terminate(resource process)
179+
kill a process opened by proc_open */
180+
PHP_FUNCTION(proc_terminate)
181+
{
182+
zval *zproc;
183+
struct php_process_handle *proc;
184+
185+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zproc) == FAILURE) {
186+
RETURN_FALSE;
187+
}
188+
189+
ZEND_FETCH_RESOURCE(proc, struct php_process_handle *, &zproc, -1, "process", le_proc_open);
190+
191+
#ifdef PHP_WIN32
192+
TerminateProcess(proc->child, 255);
193+
#else
194+
kill(proc->child, SIGTERM);
195+
#endif
196+
197+
zend_list_delete(Z_LVAL_P(zproc));
198+
RETURN_LONG(FG(pclose_ret));
199+
}
200+
/* }}} */
201+
202+
177203
/* {{{ proto int proc_close(resource process)
178204
close a process opened by proc_open */
179205
PHP_FUNCTION(proc_close)

0 commit comments

Comments
 (0)