Search code examples
phpcurlgetstream-io

Error connecting to getstream php


I am following the example at https://getstream.io/get_started/?language=php to understand how getstream io works. I ran into an error that got me confused.

 require_once './vendor/autoload.php';
 $client = new GetStream\Stream\Client('YOUR_API_KEY',     'API_KEY_SECRET');
$chris = $client->feed('user', 'chris');
 // I replaced Your api key and api key secret with the one         in my dashboard
// Add an activity; message is a custom field - tip: add unlimited         custom fields!
$data = array(
"actor" => "chris",
"verb" => "add",
"object" => "picture:10",
"foreign_id" => "picture:10",
"message" => "Beautiful bird. Absolutely beautiful. Phenomenal bird."
);

$chris->addActivity($data);


// jack's 'timeline' feed follows chris' 'user' feed:
$jack = $client->feed('timeline', 'jack');
$jack->followFeed('user', 'chris');


// Read the 'timeline' feed for jack, chris' post will now show up: 
$activities = $jack->getActivities(10);
var_dump($activities);

In my composer.json file I did this

       "require": {
        "get-stream/stream": "2.2.8"
        }

I tried the above code on my localhost machine on windows but got this error

Fatal error: Uncaught exception 'GuzzleHttp\ExceptionConnectException'     with message 'cURL error 28: Operation timed out after 0 milliseconds with 0 out of 0 bytes received (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)' in C:\xampp\htdocs\CorpersMate\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 186
 GuzzleHttp\Exception\ConnectException: cURL error 28: Operation timed out after 0 milliseconds with 0 out of 0 bytes received (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) in C:\xampp\htdocs\CorpersMate\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 186

any ideas guys?


Solution

  • I later found a tweak to the problem. The problem is with the guzzle library which is trying to verify my certificate. Because I needed a way to test it on local server before moving to production server, I had to modify the client constructor in the guzzle library and that solved the problem for me.

     // file name is Client.php 
    
      public function __construct(array $config = ['verify' => false]) {
        if (!isset($config['handler'])) {
            $config['handler'] = HandlerStack::create();
        }
    
        // Convert the base_uri to a UriInterface
        if (isset($config['base_uri'])) {
            $config['base_uri'] = Psr7\uri_for($config['base_uri']);
        }
    
        $this->configureDefaults($config);
    }