how to get JSON data from unusual port in php?

Multi tool use
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
php get port
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.
add a comment |
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
php get port
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
add a comment |
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
php get port
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
php get port
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.
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
add a comment |
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
add a comment |
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
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.
add a comment |
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.
add a comment |
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
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.
add a comment |
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
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.
add a comment |
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
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
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.
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.
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered 20 hours ago
AnthonyB
1,2851923
1,2851923
add a comment |
add a comment |
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.
Apepenkov is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
P52mRt3W7F87o3lHB53N9KQMnh4bY79 Nyz72
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