We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Lock an action for one current use

Hi, I have an action in a controller that should only be called once at a moment.

I thinking of something like a session information, that pretends other users from invoking the action after somebody else already has called it. I cannot use session objects, because they are only accessible for a certain user, but not to all.

After the action has completed it job it should be unlocked so that other users can access it again.

Thank you!

What about user cookies?

A Redis/Beanstalk server could also work, albeit it needs more coding to set up



1.1k
Accepted
answer
edited Aug '16

Thank you for your replies

I realised it now by creating a temporary lock file and writing the session ID to it. So everytime a different user wants to invoke the action, I check with an ACL if the lock file exists and if the invoking user has the same session ID as in the lock file or not.

It works fine!

You can also go with libMemcached to store your ACL. But if it's only one locked resource... even file should be enough.

@Ovomaltine85 Well, discussion may be closed?

Thank you for your help!

Discussion can be closed now