Home > Software design >  PHP file_get_content issue
PHP file_get_content issue

Time:04-08

so I have a webservice running on a Windows machine with a static IP adress and an open port. The webservice provides some json data. When accessing the IP adress and port from the browser the json is being displayed just fine. [Sample json data from browser: ]

What I want to do now is fetch the data from this machines' service with php on a website.

I have the following php code on the website:

<?php
              $url = 'http://ip-of-the-machine:port/url?params';
              $result = file_get_contents($url);
              $json = json_decode($result);
              var_dump(json_decode($result, true))
?>

When I visit the site the code is on, the page is tuck loading infinetly.

When passing 'https://jsonplaceholder.typicode.com/posts/1' as the url paramter, the sample json data from this website is being displayed. In the php.ini file allow_url_fopen is set to "true".

So I assume that there is an issue with the source of my json data on my machine where the service is running. Do you have experiance with this issue? What is the problem here?

Thank you!

CodePudding user response:

I would suggest running this with enter image description here

CodePudding user response:

As it turns out, there was an internal problem with the hosting provider for the website where I run the PHP script that calls the URL to fetch the JSON.

They resolved the issue and now both cURL requests and file_get_contents() work just fine. Thank you all!

  • Related