This is likely a common error yet might be hard to detect. If you run shell_exec(), make sure to use the full path to the binary file. It might be obvious but many for convenience does not do so, including myself at times. You forget that .bashrc does these for you while running PHP script via crontab is entirely different.
For example, shell_exec(‘ifconfig’) returned empty (it happened at times, on different servers, intermittently, not always, that made thing even harder to understand). However, the path was the issue since the logic only went through in certain cases and it worked 2/4 servers. Weird! And if you run the script directly, it gets your path. Running it via cron does not have that luxury so you need the full path: shell_exec(‘/sbin/ifconfig’); Oh well, lesson learned.