how to get JSON data from unusual port in php?











up vote
1
down vote

favorite












i have scout_realtime, and i want to get stats.json from it. in debug it looks like



91.205.168.39 - - [10/Nov/2018:09:54:22 CET] "GET /stats.json HTTP/1.1" 200 3896
http://188.165.3.*:5556/ -> /stats.json


how to get it manially? I tried to do something like this:



$status = file_get_contents('http://188.165.3.*:5556/stats.gson')


but it doesnt work










share|improve this question







New contributor




Apepenkov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Welcome on SO. Just a note about a reproducible example. As said in the how to ask guide, when you ask a question it is important to explain what doesn't work, what error you get, and to give a minimalist reproducible example that we can run on our machine.
    – AnthonyB
    20 hours ago















up vote
1
down vote

favorite












i have scout_realtime, and i want to get stats.json from it. in debug it looks like



91.205.168.39 - - [10/Nov/2018:09:54:22 CET] "GET /stats.json HTTP/1.1" 200 3896
http://188.165.3.*:5556/ -> /stats.json


how to get it manially? I tried to do something like this:



$status = file_get_contents('http://188.165.3.*:5556/stats.gson')


but it doesnt work










share|improve this question







New contributor




Apepenkov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Welcome on SO. Just a note about a reproducible example. As said in the how to ask guide, when you ask a question it is important to explain what doesn't work, what error you get, and to give a minimalist reproducible example that we can run on our machine.
    – AnthonyB
    20 hours ago













up vote
1
down vote

favorite









up vote
1
down vote

favorite











i have scout_realtime, and i want to get stats.json from it. in debug it looks like



91.205.168.39 - - [10/Nov/2018:09:54:22 CET] "GET /stats.json HTTP/1.1" 200 3896
http://188.165.3.*:5556/ -> /stats.json


how to get it manially? I tried to do something like this:



$status = file_get_contents('http://188.165.3.*:5556/stats.gson')


but it doesnt work










share|improve this question







New contributor




Apepenkov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











i have scout_realtime, and i want to get stats.json from it. in debug it looks like



91.205.168.39 - - [10/Nov/2018:09:54:22 CET] "GET /stats.json HTTP/1.1" 200 3896
http://188.165.3.*:5556/ -> /stats.json


how to get it manially? I tried to do something like this:



$status = file_get_contents('http://188.165.3.*:5556/stats.gson')


but it doesnt work







php get port






share|improve this question







New contributor




Apepenkov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Apepenkov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Apepenkov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 21 hours ago









Apepenkov

61




61




New contributor




Apepenkov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Apepenkov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Apepenkov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Welcome on SO. Just a note about a reproducible example. As said in the how to ask guide, when you ask a question it is important to explain what doesn't work, what error you get, and to give a minimalist reproducible example that we can run on our machine.
    – AnthonyB
    20 hours ago


















  • Welcome on SO. Just a note about a reproducible example. As said in the how to ask guide, when you ask a question it is important to explain what doesn't work, what error you get, and to give a minimalist reproducible example that we can run on our machine.
    – AnthonyB
    20 hours ago
















Welcome on SO. Just a note about a reproducible example. As said in the how to ask guide, when you ask a question it is important to explain what doesn't work, what error you get, and to give a minimalist reproducible example that we can run on our machine.
– AnthonyB
20 hours ago




Welcome on SO. Just a note about a reproducible example. As said in the how to ask guide, when you ask a question it is important to explain what doesn't work, what error you get, and to give a minimalist reproducible example that we can run on our machine.
– AnthonyB
20 hours ago












2 Answers
2






active

oldest

votes

















up vote
0
down vote













$url = 'http://188.165.3.*:5556/stats.json';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);


ok i made it myself :D






share|improve this answer








New contributor




Apepenkov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    up vote
    0
    down vote













    You have several possibilities to fetch your datas.



    Firstly you can use cURL. CURL is really good to send requests. As you showed in your own answer you can send an HTTP request in only few lines. I won't show a CURL example because it's already done in your answer.

    Please note that you can use libraries like Guzzle to send requests, it's easier.



    Then, I'm not sure about what doesn't work in your code, but it is possible to fetch datas on a given port using file_get_contents. Here is the little example tested with PHP 7.2.10.



    server.php



    <?php

    echo 'Hi from server';


    client.php



    <?php
    echo file_get_contents('http://localhost:8080/server.php');


    server.php acts as the server you are trying to hit. It's supposed to return a simple string.



    client.php is the script that's trying to fetch the datas.



    Then if you run php -S localhost:8080 -t . in the directory where server.php is, you can execute the client.



    Please note that you can configure the behaviour of file_get_contents by giving it a context parameter. See the stream_context_create documentation to learn more about it.




    This answer aims to show that it is possible to fetch datas using file_get_contents, but if you need some specific parameters to fetch your datas like configuring a proxy, a port or something more complexe that just read the file, I suggest to use an HTTP-dedicated function or library, like cURL or Guzzle.







    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });






      Apepenkov is a new contributor. Be nice, and check out our Code of Conduct.










       

      draft saved


      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237431%2fhow-to-get-json-data-from-unusual-port-in-php%23new-answer', 'question_page');
      }
      );

      Post as a guest
































      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote













      $url = 'http://188.165.3.*:5556/stats.json';
      $ch = curl_init($url);
      curl_setopt($ch, CURLOPT_TIMEOUT, 5);
      curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      $data = curl_exec($ch);
      curl_close($ch);


      ok i made it myself :D






      share|improve this answer








      New contributor




      Apepenkov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















        up vote
        0
        down vote













        $url = 'http://188.165.3.*:5556/stats.json';
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $data = curl_exec($ch);
        curl_close($ch);


        ok i made it myself :D






        share|improve this answer








        New contributor




        Apepenkov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.




















          up vote
          0
          down vote










          up vote
          0
          down vote









          $url = 'http://188.165.3.*:5556/stats.json';
          $ch = curl_init($url);
          curl_setopt($ch, CURLOPT_TIMEOUT, 5);
          curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
          $data = curl_exec($ch);
          curl_close($ch);


          ok i made it myself :D






          share|improve this answer








          New contributor




          Apepenkov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          $url = 'http://188.165.3.*:5556/stats.json';
          $ch = curl_init($url);
          curl_setopt($ch, CURLOPT_TIMEOUT, 5);
          curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
          $data = curl_exec($ch);
          curl_close($ch);


          ok i made it myself :D







          share|improve this answer








          New contributor




          Apepenkov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          share|improve this answer



          share|improve this answer






          New contributor




          Apepenkov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          answered 21 hours ago









          Apepenkov

          61




          61




          New contributor




          Apepenkov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          New contributor





          Apepenkov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          Apepenkov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.
























              up vote
              0
              down vote













              You have several possibilities to fetch your datas.



              Firstly you can use cURL. CURL is really good to send requests. As you showed in your own answer you can send an HTTP request in only few lines. I won't show a CURL example because it's already done in your answer.

              Please note that you can use libraries like Guzzle to send requests, it's easier.



              Then, I'm not sure about what doesn't work in your code, but it is possible to fetch datas on a given port using file_get_contents. Here is the little example tested with PHP 7.2.10.



              server.php



              <?php

              echo 'Hi from server';


              client.php



              <?php
              echo file_get_contents('http://localhost:8080/server.php');


              server.php acts as the server you are trying to hit. It's supposed to return a simple string.



              client.php is the script that's trying to fetch the datas.



              Then if you run php -S localhost:8080 -t . in the directory where server.php is, you can execute the client.



              Please note that you can configure the behaviour of file_get_contents by giving it a context parameter. See the stream_context_create documentation to learn more about it.




              This answer aims to show that it is possible to fetch datas using file_get_contents, but if you need some specific parameters to fetch your datas like configuring a proxy, a port or something more complexe that just read the file, I suggest to use an HTTP-dedicated function or library, like cURL or Guzzle.







              share|improve this answer

























                up vote
                0
                down vote













                You have several possibilities to fetch your datas.



                Firstly you can use cURL. CURL is really good to send requests. As you showed in your own answer you can send an HTTP request in only few lines. I won't show a CURL example because it's already done in your answer.

                Please note that you can use libraries like Guzzle to send requests, it's easier.



                Then, I'm not sure about what doesn't work in your code, but it is possible to fetch datas on a given port using file_get_contents. Here is the little example tested with PHP 7.2.10.



                server.php



                <?php

                echo 'Hi from server';


                client.php



                <?php
                echo file_get_contents('http://localhost:8080/server.php');


                server.php acts as the server you are trying to hit. It's supposed to return a simple string.



                client.php is the script that's trying to fetch the datas.



                Then if you run php -S localhost:8080 -t . in the directory where server.php is, you can execute the client.



                Please note that you can configure the behaviour of file_get_contents by giving it a context parameter. See the stream_context_create documentation to learn more about it.




                This answer aims to show that it is possible to fetch datas using file_get_contents, but if you need some specific parameters to fetch your datas like configuring a proxy, a port or something more complexe that just read the file, I suggest to use an HTTP-dedicated function or library, like cURL or Guzzle.







                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  You have several possibilities to fetch your datas.



                  Firstly you can use cURL. CURL is really good to send requests. As you showed in your own answer you can send an HTTP request in only few lines. I won't show a CURL example because it's already done in your answer.

                  Please note that you can use libraries like Guzzle to send requests, it's easier.



                  Then, I'm not sure about what doesn't work in your code, but it is possible to fetch datas on a given port using file_get_contents. Here is the little example tested with PHP 7.2.10.



                  server.php



                  <?php

                  echo 'Hi from server';


                  client.php



                  <?php
                  echo file_get_contents('http://localhost:8080/server.php');


                  server.php acts as the server you are trying to hit. It's supposed to return a simple string.



                  client.php is the script that's trying to fetch the datas.



                  Then if you run php -S localhost:8080 -t . in the directory where server.php is, you can execute the client.



                  Please note that you can configure the behaviour of file_get_contents by giving it a context parameter. See the stream_context_create documentation to learn more about it.




                  This answer aims to show that it is possible to fetch datas using file_get_contents, but if you need some specific parameters to fetch your datas like configuring a proxy, a port or something more complexe that just read the file, I suggest to use an HTTP-dedicated function or library, like cURL or Guzzle.







                  share|improve this answer












                  You have several possibilities to fetch your datas.



                  Firstly you can use cURL. CURL is really good to send requests. As you showed in your own answer you can send an HTTP request in only few lines. I won't show a CURL example because it's already done in your answer.

                  Please note that you can use libraries like Guzzle to send requests, it's easier.



                  Then, I'm not sure about what doesn't work in your code, but it is possible to fetch datas on a given port using file_get_contents. Here is the little example tested with PHP 7.2.10.



                  server.php



                  <?php

                  echo 'Hi from server';


                  client.php



                  <?php
                  echo file_get_contents('http://localhost:8080/server.php');


                  server.php acts as the server you are trying to hit. It's supposed to return a simple string.



                  client.php is the script that's trying to fetch the datas.



                  Then if you run php -S localhost:8080 -t . in the directory where server.php is, you can execute the client.



                  Please note that you can configure the behaviour of file_get_contents by giving it a context parameter. See the stream_context_create documentation to learn more about it.




                  This answer aims to show that it is possible to fetch datas using file_get_contents, but if you need some specific parameters to fetch your datas like configuring a proxy, a port or something more complexe that just read the file, I suggest to use an HTTP-dedicated function or library, like cURL or Guzzle.








                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 20 hours ago









                  AnthonyB

                  1,2851923




                  1,2851923






















                      Apepenkov is a new contributor. Be nice, and check out our Code of Conduct.










                       

                      draft saved


                      draft discarded


















                      Apepenkov is a new contributor. Be nice, and check out our Code of Conduct.













                      Apepenkov is a new contributor. Be nice, and check out our Code of Conduct.












                      Apepenkov is a new contributor. Be nice, and check out our Code of Conduct.















                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237431%2fhow-to-get-json-data-from-unusual-port-in-php%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest




















































































                      Popular posts from this blog

                      Florida Star v. B. J. F.

                      Error while running script in elastic search , gateway timeout

                      Adding quotations to stringified JSON object values