在与paypal集成时,我一直收到这个警告:PHP警告:fgets()期望参数1是resource,给定布尔值


I keep on getting this warning while integrating with paypal: PHP Warning: fgets() expects parameter 1 to be resource, boolean given

可能重复:
mysql_fetch_array()期望参数1是资源,在select 中给定布尔值

$url = $this->getAppParam('sandbox') ? 'www.sandbox.paypal.com' : 'www.paypal.com';
// OCT 31,2011 : now paypal uses ssl:// in url and port 443
$fp = fsockopen ('ssl://'.$url , 443, $errno, $errstr, 30);
XiError::assert($fp);

// post data back to PayPal system to validate
$header  = "POST /cgi-bin/webscr HTTP/1.0'r'n";
$header .= "Host: $url'r'n";
$header .= "Content-Type: application/x-www-form-urlencoded'r'n";
$header .= "Content-Length: " . strlen($req) . "'r'n'r'n";
fputs ($fp, $header . $req);
// read the response data now
$return = false;
while( ! feof($fp)){
    //XITODO : Add this to tmp log file
    $response = fgets ($fp, 1024); //echo $res;
    if (strcmp ($response, 'VERIFIED') == 0) {
    $return = true;
    }
    if (strcmp ($response, 'INVALID') == 0) {
        $return = false;
    }
}

XiError::断言

static function assert($condition, $msg = '', $type = self::ERROR)
    {
        // assert only if in debug mode
        if($condition || !(JDEBUG)){
            return true;
        }
        //raise error
        if($type == self::ERROR){
            self::raiseError('XI-ERROR', $msg);
        }
        //raise warning
        if($type == self::WARNING){
            self::raiseWarning('XI-WARNING', $msg);
        }
        // enqueue message
        XiFactory::getApplication()->enqueueMessage('XI-WARNING : '.$msg);
    }

这是我正在使用的代码。它正在生成警告PHP Warning: fgets() expects parameter 1 to be resource, boolean given in /var/www/****每秒50次。这导致我的服务器上出现4 GB的错误日志。知道吗?

不要使用套接字!在php中使用CURL。当套接字不工作时,Curl是php中的最佳选项。