Bitcoin Forum
December 13, 2017, 01:51:41 AM *
News: Latest stable version of Bitcoin Core: 0.15.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: PHP check server status (online offline)  (Read 2349 times)
TAiS46
Full Member
***
Offline Offline

Activity: 222



View Profile WWW
October 17, 2012, 07:43:18 PM
 #1

Hey,

I am trying to get the server status with PHP. Is the Server offline or online.

Code:
<?php
ini_set
("display_errors"TRUE);
include(
'./jsonRPCClient.php');
$bitcoin = new jsonRPCClient('http://bla:bla@111.111.111.111:8332/');
if (
$bitcoin) {
  echo 
"online";
} else {
  echo 
"offline";
}
?>


dose not work, any idea?
1513129901
Hero Member
*
Offline Offline

Posts: 1513129901

View Profile Personal Message (Offline)

Ignore
1513129901
Reply with quote  #2

1513129901
Report to moderator
1513129901
Hero Member
*
Offline Offline

Posts: 1513129901

View Profile Personal Message (Offline)

Ignore
1513129901
Reply with quote  #2

1513129901
Report to moderator
1513129901
Hero Member
*
Offline Offline

Posts: 1513129901

View Profile Personal Message (Offline)

Ignore
1513129901
Reply with quote  #2

1513129901
Report to moderator
Satoshi is no god. He did not come down from the mountain with 10 golden rules engraved in stone for no one to question.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
Raoul Duke
aka psy
Legendary
*
Offline Offline

Activity: 1456



View Profile
October 17, 2012, 07:49:10 PM
 #2

Code:
<?php
ini_set
("display_errors"TRUE);
include(
'./jsonRPCClient.php');
$bitcoin = new jsonRPCClient('http://bla:bla@111.111.111.111:8332/');
$getinfo $bitcoin->getinfo();
if (
$getinfo != '') {
  echo 
"online";
} else {
  echo 
"offline";
}
?>



Try that. Or something alike. the new jsonRPCClient command only opens the connection, you need to ask something to the server to get a response.

TAiS46
Full Member
***
Offline Offline

Activity: 222



View Profile WWW
October 17, 2012, 07:53:40 PM
 #3

already tried.
Getting an 403 Forbidden error page.
Raoul Duke
aka psy
Legendary
*
Offline Offline

Activity: 1456



View Profile
October 17, 2012, 07:55:59 PM
 #4

already tried.
Getting an 403 Forbidden error page.

The credentials are wrong, most likely.

Maybe this is useful:
Source code: https://github.com/mikegogulski/bitcoin-php
Documentation: http://code.gogulski.com/bitcoin-php

BCB
CTG
VIP
Legendary
*
Offline Offline

Activity: 1050


BCJ


View Profile
October 17, 2012, 08:12:32 PM
 #5

Are you making the call from a second box?

If credentials were wrong you'd be getting "Unable to connect to ..." with display errors.

Original code works.
Raoul Duke
aka psy
Legendary
*
Offline Offline

Activity: 1456



View Profile
October 17, 2012, 08:19:57 PM
 #6

Are you making the call from a second box?
ah!

rpcallowip=xxx.xxx.xxx.xxx

Tongue good call
That 403 would be returned if the flag was not set on bitcoin.conf Wink

TAiS46
Full Member
***
Offline Offline

Activity: 222



View Profile WWW
October 17, 2012, 08:21:59 PM
 #7

rpcallow etc is all set!
if the server is online, $bitcoin->getinfo(); works.

I am trying now to get the status with fsockopen or other php commands hmmm
BCB
CTG
VIP
Legendary
*
Offline Offline

Activity: 1050


BCJ


View Profile
October 17, 2012, 08:26:27 PM
 #8

if rpc allow was not set you'd be getting "failed to open stream: Connection refused"
TAiS46
Full Member
***
Offline Offline

Activity: 222



View Profile WWW
October 17, 2012, 08:30:03 PM
 #9

Found a solution:

Code:
<?php
 $ch 
curl_init();
 
 
curl_setopt($chCURLOPT_URL"http://**:**@111.111.111.111:8332/");
 
curl_setopt($chCURLOPT_HEADER0);
 
curl_setopt($chCURLOPT_RETURNTRANSFERtrue); 
 
 
$res curl_exec($ch);
 
curl_close($ch);
 
 if(
$res) {
   echo 
"onlin";
 } else {
   echo 
"offline";
 }
?>

BCB
CTG
VIP
Legendary
*
Offline Offline

Activity: 1050


BCJ


View Profile
October 17, 2012, 08:32:40 PM
 #10

are you on shared boxes?  sounds like a file or folder permission issue
TAiS46
Full Member
***
Offline Offline

Activity: 222



View Profile WWW
October 17, 2012, 08:35:09 PM
 #11

no, everything dose work, dose someone try out to get the offline status?
i dont think so. using now the curl methode Smiley
kjj
Legendary
*
Offline Offline

Activity: 1302



View Profile
October 21, 2012, 03:47:38 PM
 #12

How about a try/catch block?

Code:
<?php
ini_set
("display_errors"TRUE);
include(
'./jsonRPCClient.php');

try{
 
$bitcoin = new jsonRPCClient('http://bla:bla@111.111.111.111:8332/');
 
$getinfo $bitcoin->getinfo();
  echo 
"online";
}catch(
Exception $e){
  echo 
"offline: $e";
}
?>


p2pcoin: a USB/CD/PXE p2pool miner - 1N8ZXx2cuMzqBYSK72X4DAy1UdDbZQNPLf - todo
I routinely ignore posters with paid advertising in their sigs.  You should too.
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!