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

fix shmop_open(): unable to attach or create shared memory segment No… #18

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

WINROL
Copy link

@WINROL WINROL commented Jun 30, 2020

… such file or directory

@@ -26,7 +26,7 @@ public function __construct()
# Avoid creating 2 instances using the same memory segment
usleep(1000);

$this->key = (int) (microtime(true) * 1000);
$this->key = (int) (microtime(true) * 1000) - random_int(1, 999);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain more about the problem and why you've approached the fix in this way?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think mayby it creating 2 instances using the same memory segment, and this commit fixed it problem on our production server.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm ok, I can see how that could happen, in which case we should remove the usleep() above.

But also it would probably be safer to always append the random number to the end, rather than adjusting the timestamp, otherwise the following would still give duplicates:
1593524164.4012 - random 3012 = 15935241641000
1593524164.5024 - random 4024 = 15935241641000
Vs appending:
1593524164.4012 . random 3012 = 159352416440123012
1593524164.5024 . random 4024 = 159352416450244024

What do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we can rm usleep. about concat i test and error still exists.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

echo (int) (microtime(true) * 1000) - random_int(1, 999) . PHP_EOL; echo (int) (microtime(true) * 1000) - random_int(1, 999) . P
HP_EOL; ";
1593525307693
1593525307786

@duncan3dc duncan3dc added the bug label Jun 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants