Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: exec(): Unable to fork in PHP

Tags:

php

windows

cmd

I'm using php 5 apache on windows server 2008, I have disabled IIS.

I m using exec command in my PHP script and it was working fine but today I got an error:

Warning: exec(): Unable to fork 

I gave permissions to cmd.exe in C:\Windows\System32 folder but this did not fix the problem.

like image 552
Kamran Akhter Avatar asked Dec 12 '11 13:12

Kamran Akhter


People also ask

What does Unable to fork mean?

fork() usually fails because necessary system resources are exhausted, it is likely that memory limits or the maximum number of open processes per system is reached.

How do you check if exec is enabled in PHP?

php phpinfo(); ?> You can search for disable_functions and if exec is listed it means it is disabled. To enable it just remove the exec from the line and then you need to restart Apache and you will be good to go. If exec is not listed in the disable_functions line it means that it is enabled.


2 Answers

Specifically which permissions did you give to who? Probably not to the right user..

Run this php script:

echo 'Script is executed by: ' . get_current_user() . getmygid();

It will tell you which user is running the PHP scripts and therefore which user to grant permissions to cmd.exe.

like image 56
Richard EB Avatar answered Oct 22 '22 21:10

Richard EB


In 64-bit windows (e.g server 2008), theres a folder named c:\windows\syswow64, that contains all executables/dll, that are required by a 32 bit app. installed on your 64-bit machine. Make sure your required 32-bit .exe/dll etc is placed in that folder. if you cant find it there you will have to put a 32-bit version of the required .exe/dll there.So this can used by yopur app/process.

Now when your 32-bit application/process executes, windows will automatically redirect your process to execute required app in syswow64 folder.

Hopefully that should resolve your compatibility issue.

like image 3
Farooq Avatar answered Oct 22 '22 21:10

Farooq