I have this PHP code:$execout=exec('ssh root@xxx.xxx.xxx.xx sudo /etc/init.d/smokeping reload',$output1,$result);if($result !=0){    echothat can't reload;}else{    echo successfully reloaded;}in this code, always gives the $result = 0. Why is that? Sometimes if smokeping has an error, it shows that error when bellow command typed in command line,ssh root@xxx.xxx.xxx.xx sudo /etc/init.d/smokeping reloadthen it gives this error messege.* Reloading latency logger daemon configuration...ERROR: can't open /etc/smokeping/devices/errorfilename: No such file or   directory ...done.so it has an error, but $result every times gives the same as 0 . (Whether it had an error or not)Why does the exec command behaves like this(in php and CLI)?
PHP exec command has the result 0 even if an error occurs
ssh;php;exit;exec
I found a little answer for that.for the above code I put 2>&1 at the end. As $execout=exec('ssh root@xxx.xxx.xxx.xx sudo /etc/init.d/smokeping reload 2>&1',$output1,$result);When there is an error occurs in the application that I'm going to reload(smokeping), print_r($output); gives the error asArray ( [0] => * Reloading latency logger daemon configuration... [1] => ERROR: can't open /etc/smokeping/devices/errorfilename: No such file or directory [2] => ...done. )Now I can handle it from here.Thank you all .  