Couple of reasons for this, but both point to the php.ini files that are being used by Apache and the CLI. Look at the output of a phpinfo() for each to see the differences.
Now, I suspect that either warnings are not set to display on the CLI and you actually do still have the warning (you can check the logs to see if the warning shows there) or the CLI php.ini file has different settings regarding the socket connections.