Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High Apache CPU with mosquitto #136

Open
itdontgo opened this issue Apr 11, 2022 · 0 comments
Open

High Apache CPU with mosquitto #136

itdontgo opened this issue Apr 11, 2022 · 0 comments

Comments

@itdontgo
Copy link

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);
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant