我正在尝试使用AlchemyAPI的php sdk。我正在运行他们的Github page上给出的相同示例。但是当我尝试运行这个例子时,我得到了这个错误信息-
Warning: fclose() expects parameter 1 to be resource, boolean given in C:\wamp\www\twitter-analysis\alchemyapi.php on line 261可能的原因是什么?在alchemyapi.php中,这是出现警告的地方-
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');
}
}
}发布于 2013-10-22 07:29:34
如果fopen()成功,则返回资源;如果失败,则返回false。fopen最有可能不起作用的情况是路径无效或您没有访问资源的权限。
这里也问了一个类似的问题:https://stackoverflow.com/questions/18636680/php-warning-fclose-expects-parameter-1-to-be-resource-boolean-given
发布于 2014-07-21 14:58:46
尝试在实时服务器上进行测试。我的经验是,它在本地服务器上给出错误,而本地服务器在实时服务器上工作。
https://stackoverflow.com/questions/19490716
复制相似问题