Resolving an unable to fork PHP warning in Windows
In Windows, when trying to execute a system call from a PHP script, you receive a warning like "Warning: system() [function.system]: Unable to fork". A related warning message is "Warning: shell_exec() [function.shell-exec]: Unable to execute"
<?php // print output of shell command executed with backtick operator print htmlentities(`dir`); ?>
The most likely cause is insufficient permissions to execute system calls in the web server environment.
You need to give the Internet Guest Account (a.k.a. IUSR_MachineName or simply IUSR) read and execute permission to the command shell program,
cmd.exe. Typically, permission to this file is explicitly denied as a security measure.
- Open Windows Explorer and browse to the
- Right-click on
cmd.exe, and select Properties....
- Click the Security tab. See image below.
- If Internet Guest Account is not already listed, then click Add, then Advanced..., then Find Now.
- Scroll down to and select IUSR_MachineName, where MachineName is the name of your computer.
- Click OK twice to return to the Security tab.
- Select Internet Guest Account and then click the box under Allow for Read & Execute.
- Click OK.
It is a very bad idea to allow unvalidated input to any system calls. Remember to use escapeshellcmd for any commands that will contain user input.
You will have to give IUSR appropriate permissions to any other files and folders that the PHP script will access.
Read the Program Execution Functions reference materials in the PHP manual for more information.
Windows XP, 2000, 2003, PHP, IIS 5.1, fork, system, exec, passthru, shell_exec, backtick operator
Disclaimer: This content is provided as-is. The information may be incorrect.