Consider the following system configurations:
- Fedora 27
- SELinux enabled
- Apache/2.4.33
- PHP 7.1.17
And the below code snippet that is used to issue an http request to Sphere-Engine Compilers API:
$ch = curl_init('http://xxxxxxxx.compilers.sphere-engine.com/api/v4/test?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 3.0);
$x = curl_exec($ch);
print_r($x);
The above script works completely fine when I run the following CLI:
php script.php
And I get the intended output.
However, when I try to run it through the web browser it produces:
CURLE_COULDNT_CONNECT (7) Failed to connect() to host or proxy.
I have found many suggestions such as adding
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
Which wasn't really a solution for me. Turning off SELinux which I will not do.
Note: The URL itself is working fine when I issue it and gives me the intended output too.
Any suggestions? Thanks in advance.