Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't connect to RPC on php server #15426

Closed
ozergul opened this issue Nov 5, 2017 · 6 comments
Closed

Can't connect to RPC on php server #15426

ozergul opened this issue Nov 5, 2017 · 6 comments

Comments

@ozergul
Copy link

ozergul commented Nov 5, 2017

Hello guys.
I am using php to connect RPC server. In localhost, everything works fine. I moved my files to host to test and I realised that $geth->Method_Name() is not working.

If I print_r($geth), here is the result.

GethApi Object ( [_options:protected] => Array ( [version] => 2.0 [host] => 165.227.103.219 [port] => 8545 [assoc] => 1 ) [_address:protected] => http://165.227.103.219:8545 [_id:protected] => 0 )

But if I wanna get block number with $geth->eth_blockNumber() here is the result in localhost:

4495121

But in php server:

Fatal error: Uncaught exception 'RuntimeException' with message 'Failed to connect to 165.227.103.219 port 8545: Connection refused' in /home/crypuekb/public_html/GethApi.php:86

  | Stack trace:
  | #0 /home/crypuekb/public_html/GethApi.php(152): GethApi->;__call('eth_blockNumber', Array)
  | #1 /home/crypuekb/public_html/geth.php(14): GethApi->eth_blockNumber()
  | #2 /home/crypuekb/public_html/php/db.php(7): require_once('/home/crypuekb/...')
  | #3 /home/crypuekb/public_html/register.php(4): include('/home/crypuekb/...')
  | #4 {main}
  | thrown in /home/crypuekb/public_html/GethApi.php on line 86

Here is the line 86:

throw new \RuntimeException(curl_error($curl), curl_errno($curl));

I am using this command to start geth server:

geth --rpcapi "web3,eth,personal"  --rpc --rpcaddr "0.0.0.0" --rpccorsdomain "*" --light

As I said, everything works perfect on localhost.. Also my php server and ethereum server is based on different hosts. And I tried my php codes at three different hosts.

@ligi
Copy link
Member

ligi commented Nov 5, 2017

Please ask this question on https://ethereum.stackexchange.com/

@vickyzare567
Copy link

Hey
Have you find any solution ...
Please Let me know if yes
i'm stuck in same problem

Thanks

@ozergul
Copy link
Author

ozergul commented Nov 8, 2017 via email

@karalabe
Copy link
Member

karalabe commented Nov 8, 2017

Connection refused means you have a firewall blocking the port. Check your router and/or OS.

@holiman
Copy link
Contributor

holiman commented Nov 10, 2017

A couple of things to check:

  • Check that it's indeed listening where you want it to: netstat --nlp should show you geth listening at 0.0.0.0 port 8545.
  • Check that there's no local firewall, sudo iptables -L
  • If there's nothing on the machine that blocks it, the problem is somewhere between the server and the client, e.g. some external firewall.

A note, though; it's not safe to expose the personal api if there are any accounts with ether on them on the - in fact, I'd recommend not to expose the node API to the internet at all if it holds funds.

I'm closing this bug since it does not appear to be a bug in geth.

@stale
Copy link

stale bot commented Nov 11, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot closed this as completed Dec 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants