Can I persist a flag across all sessions?

39 Views Asked by At

I have an expensive operation that runs in my PHP application when the /api/replicate endpoint is requested. The operation takes roughly 30 seconds, so I want to prevent this endpoint from being called again until the operation is complete.

Normally, I would store a flag in the session data that indicates whether the operation is running or not and check this flag before running the operation. However, session data is specific to an individual user/browser. I would want this flag to persist across all sessions and processes (I am using Apache HTTP Server) so that another user cannot run the operation if it is already running.

I considered using a lock file and also considered persisting this flag to a database. However, I think the best solution would involve storing the flag in memory somewhere so that it does not persist if Apache is restarted.

Is there a way to globally persist a flag like this?

0

There are 0 best solutions below