---
title: "PHP pcntlexec Command Execution"
section: "Network Services"
sectionSlug: "network-services-pentesting"
sourcePath: "src/network-services-pentesting/pentesting-web/php-tricks-esp/php-useful-functions-disable_functions-open_basedir-bypass/disable_functions-bypass-php-4-greater-than-4.2.0-php-5-pcntl_exec.md"
sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/network-services-pentesting/pentesting-web/php-tricks-esp/php-useful-functions-disable_functions-open_basedir-bypass/disable_functions-bypass-php-4-greater-than-4.2.0-php-5-pcntl_exec.md"
sha: "188de82beb54e70956b2952367a0af91d26758b8"
isIndex: false
modified: true
license: "CC-BY-NC-4.0"
---
# PHP `pcntl_exec` Command Execution
If the PCNTL extension is loaded and `pcntl_exec` is not itself disabled, the function can start an executable even when more familiar command-execution functions are listed in `disable_functions`. `pcntl_exec` replaces the current process; it does not create a child process, and its arguments must be supplied as an array.[[1]](#references)
The following minimal example executes `ls -l /var/tmp`. It is adapted from an older `disable_functions` bypass demonstration.[[2]](#references)
```php
```
This technique is Unix-specific and can terminate or replace a PHP worker process. Use it only in an authorized test environment.[[1]](#references)
For a request-driven lab check, keep the argument as an array; passing a string as the second parameter is invalid. Because `pcntl_exec()` replaces the PHP process, command output is written directly to the current response or process streams rather than returning to PHP:[[1]](#references)
```php
```
## References
- [1] [PHP Manual - `pcntl_exec`](https://www.php.net/manual/en/function.pcntl-exec.php)
- [2] [SafeBuff - `disable_functions` bypass (archived)](https://web.archive.org/web/20170801153107/http://blog.safebuff.com:80/2016/05/06/disable-functions-bypass/)