PHP Warning: exec() unable to fork

前端 未结 5 790
盖世英雄少女心
盖世英雄少女心 2020-12-01 21:46

So here is a little background info on my setup. Running Centos with apache and php 5.2.17. I have a website that lists products from many different retailers websites. I

相关标签:
5条回答
  • 2020-12-01 22:12

    Process limit

    "Is there a process limit I should look into"

    It's suspected somebody (system admin?) set limitation of max user process. Could you try this?

    $ ulimit -a
    ....
    ....
    max user processes              (-u) 16384
    ....
    

    Run preceding command in PHP. Something like :

    echo system("ulimit -a");
    

    I searched whether php.ini or httpd.conf has this limit, but I couldn't find it.

    Error Handling

    "even a better way to handle these processes as to get around the error all together?"

    The third parameter of exec() returns exit code of $cmd. 0 for success, non zero for error code. Refer to http://php.net/function.exec .

    exec($cmd, &$output, &$ret_val);
    
    if ($ret_val != 0)
    {
        // do stuff here
    }
    else
    {
        echo "success\n";
    }
    
    0 讨论(0)
  • 2020-12-01 22:12

    I ran into same problem and I tried this and it worked for me;

    ulimit -n 4096
    
    0 讨论(0)
  • 2020-12-01 22:14

    For anyone else who comes across this issue, it could be several problems as outlined in this question's answer.

    However, my problem was my nginx user did not have a proper shell to execute the commands I wanted. Adding .bashrc to the nginx user's home directory fixed this.

    0 讨论(0)
  • 2020-12-01 22:20

    The problem is often caused by the system or the process or running out of available memory. Be sure that you have enough by running free -m. You will get a result like the following:

    total used free shared buffers cached Mem: 7985 7722 262 19 189 803 -/+ buffers/cache: 6729 1255 Swap: 0 0 0

    The buffers/cache line is what you want to look at. Notice free memory is 1255 MB on this machine. When running your program keep trying free -m and check free memory to see if this falls into the low hundreds. If it does you will need to find a way to run you program while consumer less memory.

    0 讨论(0)
  • 2020-12-01 22:29

    In my case (large PHPUnit test suite) it would say unable to fork once the process hit 57% memory usage. So, one more thing to watch for, it may not be a process limit but rather memory.

    0 讨论(0)
提交回复
热议问题