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

Is it normal when i publish some messages like this? #11

Closed
fengrujun opened this issue Mar 27, 2014 · 4 comments
Closed

Is it normal when i publish some messages like this? #11

fengrujun opened this issue Mar 27, 2014 · 4 comments

Comments

@fengrujun
Copy link

mytest.php:
$client = new Mosquitto\Client();
$client->connect("x.x.x.x", 1883, 60);

while ($client->loop() == 0) {
$message = "Test message at " . date("Y-m-d H:i:s");
$client->publish('mytopic', $message, 0, false);
$client->loop();
sleep(1);
}

When i first use browser open mytest.php ,the subscribe side receive the message sucessfully,but i close the page,the subscribe side still can receive the message ,what's going wrong?

@pastinepolenta
Copy link

Not completely sure but I thing the php script will keep running until something appear on the browser page. even if you close the page I assume the web server keeps the script active.

@mgdm
Copy link
Owner

mgdm commented Mar 27, 2014

Yeah, that'll be it. It won't know the connection has closed until you try and write to it.

On 27 Mar 2014, at 15:01, stilllife00 [email protected] wrote:

Not completely sure but I thing the php script will keep running until something appear on the browser page. even if you close the page I assume the web server keeps the script active.


Reply to this email directly or view it on GitHub.

@fengrujun
Copy link
Author

it's weird,lookat the following code:
$client->connect($host, $port, 60);
for($i = 0;$i<$num;$i++)
{
$message = array
(
'TaskId'=>'1',
'UnitPrice'=>'1',
'TradeId'=>$tradeId,
'FileType' => 'image',
'DownloadUrl' => 'www.example.com',
);
$client->publish($topic, json_encode($message), 1, 0);

}
$client->disconnect();
unset($client);

when the $num is less than 20,the subscrive side receive the mesagges correctly,but when the $num is larger than 20 the subscrive side only can receive 20 messages..Any solution?

@mgdm
Copy link
Owner

mgdm commented Jan 28, 2016

You need to call $client->loop() to make the underlying library process its messages. I've added an example to the README.

@mgdm mgdm closed this as completed Jan 28, 2016
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

3 participants