1

Im trying to send a json event through php using a Http client in the following way :

private function postEvent(Event $event) { 
   $client = $this->getHttpClient();
   $client->setRawBody(json_encode($event));
   $client->setUri($this->getHost() . '/api/events');
   $client->setMethod('POST');
   $client->send();
}

But I am facing the below error :

Fatal error: Uncaught exception 'ErrorException' with message 'stream_socket_client(): unable to connect to localhost:8080 (Connection refused)' in /home/naikr/www/public/fieldtest/vendor/zendframework/zend-http/Zend/Http/Client/Adapter/Socket.php on line 258

Zend\Http\Client\Adapter\Exception\RuntimeException: Unable to connect to localhost:8080 . Error #0: stream_socket_client(): unable to connect to localhost:8080 (Connection refused) in /home/naikr/www/public/fieldtest/vendor/zendframework/zend-http/Zend/Http/Client/Adapter/Socket.php on line 258

Any ideas on how I can resolve this and connect to localhost:8080 ?

1 Answer 1

1

This is not a PHP problem. 'Connection refused' means either nothing is listening on port 8080, or a firewall is blocking it. One way to verify would be to try telnetting to it (telnet localhost 8080). Solve this and then try your code again.

Sign up to request clarification or add additional context in comments.

1 Comment

I figured the issue, as you had mentioned the port was listening to nothing. Thank you though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.