Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 292 Vote(s) - 3.6 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Restrict running code in Lumen route to one caller at a time

#1
I'm making a small application with Lumen that has a route that is expensive to run. I'd like to make sure that only one person can hit this route at a time. If a second person tries to hit the route while another person is running it, then the application should return a message saying something like "Please try again in a few minutes." How can I accomplish this?
Reply

#2
Use a mutex. If your app runs on a single host with a local filesystem, you can use flock:

public function my_controller() {
$fp = fopen('lockfile', 'r');
if (! flock($fp)) die('Try again later');
// do expensive thing...
funlock($fp);
fclose($fp);
}

If you have a cluster of machines, or the machine's disk are network mounted, use a database mutex. Eg, in mysql:

`do get_lock('lock');`
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through