0

I am trying to use AlchemyAPI's php sdk. I am running the same example given on their Github page. But when I try to run the example, I get this error message-

 Warning: fclose() expects parameter 1 to be resource, boolean given in C:\wamp\www\twitter-analysis\alchemyapi.php on line 261

What could be the reason? In alchemyapi.php, this is where the warning is occuring-

private function analyze($url, $params) {
        //Insert the base URL
        $url = $this->_BASE_URL . $url;

        //Add the API Key and set the output mode to JSON
        $url = $url . '?apikey=' . $this->_api_key . '&outputMode=json';

        //Add the remaining parameters
        foreach($params as $key => $value) {
            $url = $url . '&' . $key . '=' . $value;
        }

        //Create the HTTP header
        $header = array('http' => array('method' => 'POST', 'Content-type'=> 'application/x-www-form-urlencoded'));

        //Fire off the HTTP Request
        try {
            $fp = @fopen($url, 'rb',false, stream_context_create($header));
            $response = @stream_get_contents($fp);
            fclose($fp);
            return json_decode($response, true);
        } catch (Exception $e) {
            return array('status'=>'ERROR', 'statusInfo'=>'Network error');
        }
    }
}
user2510555
  • 967
  • 2
  • 8
  • 15

2 Answers2

0

fopen() returns the resource if it succeeds, and false if it didn't work. The most likely case for the fopen to not work is if the path is invalid or if you don't have access to the resource.

A similar question was asked here: https://stackoverflow.com/questions/18636680/php-warning-fclose-expects-parameter-1-to-be-resource-boolean-given

Community
  • 1
  • 1
Steve
  • 141
  • 1
  • 3
0

Try to test on live server. My experience it gives error in local server where works in live server.

Kiran
  • 1,176
  • 2
  • 14
  • 27