1
votes

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

1 Answers

1
votes

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.