0

I've my code in test server which uses file_get_contents() to get the status from a url. The test server link is: http://test1one.epizy.com/portal/test_api.php It works as it should and gives me the appropriate "Active" or "Inactive" response from the url.

But it doesn't work on the production server link and gives a blank page: http://thecreamplatform.com/portal/test_api.php The link page contains the following lines of code:

$url = "http://209.208.78.58:8085/cream/verify?msisdn=23480xxxxxxxx";

try {
    $result = file_get_contents($url);
    echo "<pre>"; print_r($result);
} catch (Exception $e) {
    echo "<h1>Error!!!</h1>", $e->getMessage(), "\n";
}

The xxxxxxxx in the above code refers to the mobile number. Can anyone please help me sort out whats causing the issue? Thanks in advance.

razn
  • 69
  • 3
  • 10
  • 3
    please define "doesn't work". Does it emit an error? Does it log an error to the logs? Does it open the wrong file? Do demons from the depths of hell itself get released into the world to consume the flesh of the wretched sinners? Without more information I'd guess it's probably a permissions issue, but that can only be a guess. – GordonM Apr 25 '18 at 08:17
  • Also, try/catch is ineffective when dealing with file_get_contents because it doesn't throw an exception, it emits a warning and returns a non-value (null, I think). – GordonM Apr 25 '18 at 08:18
  • check URL may be it's returning 404 – Vipul Solanki Apr 25 '18 at 08:31
  • file_get_contents() wil indeed never throw an Exception, but you can catch the errors (Throwable interface) `catch (\Throwable $e)`. PHP 7+ Or enable errors with `ini_set('display_errors', 1); ini_set('error_reporting', E_ALL);`, placed at the top of the file. – Dygnus Apr 25 '18 at 08:54

1 Answers1

0

Check http://php.net/file_get_contents. If the return value is NULL then the function is disabled.

Enable error reporting and the display of errors to learn more about what is going wrong.

error_reporting(~0);
ini_set('display_errors', 1);
Gaylord.A
  • 19
  • 2
  • I added the above two lines on top of my file and it gives me the this error: Warning: file_get_contents(http://209.208.78.58:8085/cream/verify?msisdn=2348062318399): failed to open stream: Connection refused in /home/thecream/public_html/portal/test_api.php on line 9 – razn Apr 25 '18 at 09:59