Skip to content

High Apache CPU with mosquitto #136

@itdontgo

Description

@itdontgo

This was a recurring problem when publishing to mosquitto.

Probably the socket closes during the read function and the fread no longer blocks the loop or something.

    while (!feof($this->socket) && $togo > 0) {
        $fread = fread($this->socket, $togo);
        $string .= $fread;
        $togo = $int - strlen($string);
    }

You need something like this:

$loops = 20;
    while (!feof($this->socket) && $togo > 0) {
		usleep(500);
        $fread = fread($this->socket, $togo);
		$loops--;
		if(!$loops){return $string;}
        $string .= $fread;
        $togo = $int - strlen($string);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions