-
Notifications
You must be signed in to change notification settings - Fork 55
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
sendAndReceive works endlessly (timeout is ignored) #73
Comments
first idea would be - maybe machine clock is being synchronized "back in time". I have to investigate how php acts when clock 'drifts'. Do you have NTP or some automatic time synchronization setup for your server? |
Though 'drifting' is possible, it is not required to explain the phenomena; since the $lastAccess resets itself at every iteration, it is very possible that $timeout did not pass yet |
You are correct. It is definitely problem when Can you modify your code (vendor folder) in production? And does that problem occur reliably? You could try $data = fread($stream, 256); // read max 256 bytes
if ($data === false) {
throw new IOException('fread error during receiveFrom');
}
if (!empty($data)) { (in addition that meanwhile I fix this in master and release new version |
…s early but `fread` does not produce data and $lastAccess getting reset and moving timeout always into future (#73)
…s early but `fread` does not produce data and $lastAccess getting reset and moving timeout always into future (#73)
It is in master branch now. I'll do proper release in couple of days |
I have made the change and lets wait and see. |
@galpeaceman are you really running same PHP process for weeks? I use this library in industrial environment (4+ year now) and out of fears of memory leaks and stuff I built my modbus poller to run X amount of time and then automatically stop/restart + guards not to run multiple instance etc. I think I'm quite paranoid :) |
Well, I did not mean it is the same PHP process.. it currently resets after 5 reads, just like you described. |
New version is published - I'll close this issue for now. And @galpeaceman thanks for pointing it out! |
I have a working app using this module.
It works perfectly for days, sampling thousands of samples from a single device.
Then, one day, the CPU goes up to 100% and works endlessly until I kill it.
I think I understand the source of the problem.
See ModbusTcpClient\Network\StreamHandler's receiveFrom method (I copied here the relevant part of the code):
So, what if fread fails very quickly (due to a connection timeout) and $dataReceived is false;
$timeSpentWaiting would be a very small number, possibly less than $timeout.
No matter, after a few tries $timeout would pass, right? No. It will never pass. Why?
Because $lastAccess is reset again to microtime(true) and the whole thing repeats itself.
I think the correct code should be:
What do you say?
The text was updated successfully, but these errors were encountered: