Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

PHP Warning: exec(): Unable to fork [rm some_file.txt] in some.php on line 111

There is a question that has been asked before about this subject PHP Warning: exec() unable to fork I have similar problem but it not the same.

ulimit -a 

core file size          (blocks, -c) 0                                        
data seg size           (kbytes, -d) unlimited                                
scheduling priority             (-e) 0                                        
file size               (blocks, -f) unlimited                                
pending signals                 (-i) 31364                                    
max locked memory       (kbytes, -l) 64                                       
max memory size         (kbytes, -m) unlimited                                
open files                      (-n) 1024                                     
pipe size            (512 bytes, -p) 8                                        
POSIX message queues     (bytes, -q) 819200                                   
real-time priority              (-r) 0                                        
stack size              (kbytes, -s) 10240                                    
cpu time               (seconds, -t) unlimited                                
max user processes              (-u) 31364                                    
virtual memory          (kbytes, -v) unlimited                                
file locks                      (-x) unlimited 

My limits are shown above and it looks like there is nothing with low limit on server that can affect this error.

I tried to unsetting variables after using them both with unset and by setting them to null to free up memory. But it has no effect.

unset($var);
$var = null;

Unable to fork error occuring because of exhausting of some resources but I can't find the reason. Can you suggest me to which logs I should look?

Any ideas or workaround for this problem?

share|improve this question
1  
Does the output from exec() give you a clue? Catch the return code and inspect it as in stackoverflow.com/questions/20648949/…. Also routing PHP Warning to ErrorException and handling them is always a good idea. – spinkus Dec 7 '16 at 7:05
    
In terms of logs. Pretty sure you'll see max user processes or whatever violation show up in /var/log/syslog. – spinkus Dec 7 '16 at 7:07
    
@S.Pinkus thanks for suggestions I will try them soon – Ferid Movsumov Dec 7 '16 at 8:21
    
@S.Pinkus There is no /var/log/syslog on server. I tried this command tail -f $( locate syslog ) – Ferid Movsumov Dec 8 '16 at 7:06
    
That's quite weird. /var/log/ is the standard place for logs. Exactly what's there depends on your logging config which should be in /etc/rsyslog.conf. cat that. It's fairly easy to see what's going where. – spinkus Dec 8 '16 at 10:15

Any ideas or workaround for this problem?

The problem is likely a flaw in your code - like it was in http://stackoverflow.com/a/20649541/2038383. So the work around is fixing it.

Can you suggest to me in which logs I should look?

There is your PHP logs, then your system / kernel logs.

You already know where to get the PHP log and what is in it by default. Unfortunately your not going to get much more out of PHP. You could catch the error yourself with set_error_handler() but that won't give you any more useful info (it'll give you PHP's "errno" but not UNIX's errno).

As for system logs; I said in comments check your syslog. There might be something in there, and it's always a good starting point. But actually you won't generally see ulimit violations in syslog. Some will get logged (example stack size generates segfault which gets logged) but many won't. This post deals with how to get logs of ulimit violations: https://unix.stackexchange.com/questions/139011/how-do-i-configure-logging-for-ulimits. Surprisingly non trivial.

The way system ulimit violations are supposed to be reported by system call is by setting an errno. For example, if max user processes is hit fork() will return EAGAIN.

So ... you need to get at that UNIX errno to know what is really going on. Unfortunately I don't think there is a way in PHP (there is posix_errno(), but pretty sure that is limited to PHP's posix_XXX function library). Also note, it's PHP generating the "Unable to fork" message. How that maps to actual system call error is not completely transparent.

So best off looking at other ways to debug of which there are plenty. Like system monitoring tools: ps, dstat, strace might be a good start.

share|improve this answer
    
Thank you very much for your detailed answer. – Ferid Movsumov Dec 8 '16 at 13:48
    
No worries, got a bit carried away looking into it :). Was fun. – spinkus Dec 8 '16 at 23:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.