Greetings dear reader! It has been a while since I wrote last time, so it is very nice to see you! And I hope this post will be interesting, and yo...
For further actions, you may consider blocking this person and/or reporting abuse
Very nice! Thank you for sharing.
In that example, even after implementing the interface, we might see a counter value > 1, right?
In a race condition where a request accesses the value before its reset...
Does having repositories in controllers constructors lead to pdo connections remaining forever open? Is there a workaround?
Once again, thanks for sharing. :-D
Thank you very much for your question. The memory is shared within the same worker, and each worker can handle one request at a time.
Let's assume we have only one worker available and two concurrent requests were sent. The following will happen:
In this case, we can't actually get the race condition, because a single worker processes requests one at a time. The race condition is possible only with multiple workers. But in this case, they don't share the memory. So it shouldn't be a concern.
I was using the following example (with 5 seconds delay):
And was sending 2 requests within 5 seconds, to emulate the race condition.
Tried single
frankenphpworker:And got the expected
1for both requests, their total execution time was around 10 seconds, as the second one was "on hold" while the first one was processing.And also checked
frankenphpwith two workers:And again expected result was returned for both requests, and the total execution time was around 5 seconds, as the second request was not waiting for the first one to be processed. The expected result is returned for both requests even without
ResetInterface. As requests are handled by different workers that don't share the memory.Dear @cviniciussdias I hope it helps with your question. Otherwise can you please provide an example to reproduce the case you are referring to?
Phanalist looks like a really useful tool: I was searching for a tool that would fail if set cyclomatic complexity would have been over a threshold and it seems it does exactly this.
Maybe I don’t have yet a real use case to test the stateless rules, but knowing this tool exists is for sure a good starting point!
Going to read the other articles in this series: that I you!
Have you tried using ResetInterface with Swoole while coroutines are enabled? A coroutine can switch requests within the same context before the reset occurs, especially if there is I/O involved.