Link to home
Start Free TrialLog in
Avatar of cescentman
cescentmanFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Not sure how to progress this PHP problem

I'm trying to connect to an API using the code I was given for the purpose below. It fails on line 9 with the error:-

"Fatal error: Using $this when not in object context"

Can someone help me understand how to resolve this?

Thanks


function get_response($res) {
    $size_packed = fread($res, 4);
    if(strlen($size_packed) == 0) { return; }
    $size = unpack("N", $size_packed);
    // This works around PHP's fread() capping at 8192 bytes
    $out = "";
    $last = "";
    for($s = $size[1]-4; $s>0; $s-=strlen($last)) {
        $last = fread($this->res, $s);
        $out.=$last;
    }
    return $out;
}

$api_host = "api.domain.com";
$api_port = 1701;
$clID = "MyID";
$pw = "MyPassword";

$res = fsockopen("tls://" . $api_host, $api_port);

get_response($res);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial