I have a very simple test script:
I had the same problem for PHP ftp ftp_connect and had to set the
setsebool -P httpd_can_network_connect=1
It's confusing because other things like fil_get_contents and curl work through PHP and apache just fine before setting that.
fil_get_contents